Service Desk Practitioners Forum
cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.NullPointerException when saving Actual Start for Work Order using web-api

Highlighted
Jeff_443
Occasional Advisor

java.lang.NullPointerException when saving Actual Start for Work Order using web-api

We are using OpenView ServiceDesk 4.5. I can't remember the service pack, it is either 13 or 15.

I am attempting to save the Actual Start date for a Work Order using the web-api, but it keeps throwing a NullPointerException. I can set the Actual Finish without any error, but Actual Start fails every time.

If I do the same thing using the client tool, it works fine. There are no UI or Database Rules that seem to be interfering.

Here's my code. Thank you in advance.

public IWorkorderHome WorkOrderHome()
{
return Session().getWorkorderHome();
}

public IWorkorderClosureCodeHome WOClosureCodeHome()
{
return Session().getWorkorderClosureCodeHome();
}

public IWorkorderStatusHome WOStatusHome()
{
return Session().getWorkorderStatusHome();
}

public Double ConvertDate(String ITORDate) throws Exception
{
// format must be 2006-11-18-19-01-01 (YYYY-MM-DD-HH-MI-SS)
String mydate[] = ITORDate.split("-");
if (mydate == null || mydate.length != 6)
{
CloseSession();
throw new Exception("Date is invalid: " + ITORDate);
}

TimeZone tz = TimeZone.getTimeZone("EET"); //Eastern European Time
java.util.Calendar cal = java.util.Calendar.getInstance(tz);
cal.set(Integer.parseInt(mydate[0]), Integer.parseInt(mydate[1])-1, Integer.parseInt(mydate[2]),
Integer.parseInt(mydate[3]), Integer.parseInt(mydate[4]), Integer.parseInt(mydate[5]));

java.util.Date dtDate = cal.getTime();

return ApiDateUtils.date2Double(dtDate);
}


/**
* Web service operation
*/
public void UpdateWorkOrder(java.lang.Long WorkOrderID, java.lang.String Status, java.lang.String ClosureCode,
java.lang.String ActualStartDate, java.lang.String ActualFinishDate) throws Exception {

IWorkorderHome myWorkOrderHome = WorkOrderHome();
IWorkorderWhere myWOWhere = myWorkOrderHome.createWorkorderWhere();
myWOWhere.addCriteriumOnID(WorkOrderID);
IWorkorder myWorkOrders[] = myWorkOrderHome.findWorkorder(myWOWhere);
if (myWorkOrders == null)
{
CloseSession();
throw new Exception("Work order could not be found for ID: " + WorkOrderID.toString());
}

if (myWorkOrders.length > 1)
{
CloseSession();
throw new Exception("Somehow, this work order id produces multiple work orders: " + WorkOrderID.toString());
}

IWorkorder myWorkOrder = myWorkOrders[0];

// Set Closure Code
if (ClosureCode != null && ClosureCode.length() > 5)
{
// codes can be: Not Implemented / Rejected, but we just want Rejected
String codes[] = ClosureCode.split("/");
ClosureCode = codes[codes.length-1].trim();

IWorkorderClosureCodeHome myClosureCodeHome = WOClosureCodeHome();
IWorkorderClosureCodeWhere myWOCCWhere = myClosureCodeHome.createWorkorderClosureCodeWhere();
myWOCCWhere.addCriteriumOnText(ClosureCode);
IWorkorderClosureCode myWOCodes[] = myClosureCodeHome.findWorkorderClosureCode(myWOCCWhere);
if (myWOCodes == null || myWOCodes.length != 1)
{
CloseSession();
throw new Exception("A work order closure code could not be found in OVSD called: " + ClosureCode);
}
else
myWorkOrder.setClosureCode(myWOCodes[0]);
}

// Set Status
if (Status != null && Status.length() > 5)
{
IWorkorderStatusHome myWOStatusHome = WOStatusHome();
IWorkorderStatusWhere myWOStatusWhere = myWOStatusHome.createWorkorderStatusWhere();
myWOStatusWhere.addCriteriumOnText(Status);
IWorkorderStatus myWOStatus[] = myWOStatusHome.findWorkorderStatus(myWOStatusWhere);
if (myWOStatus == null || myWOStatus.length != 1)
{
CloseSession();
throw new Exception("A work order status could not be found in OVSD called: " + Status);
}
else
myWorkOrder.setStatus(myWOStatus[0]);
}

// Set Actual Finish
myWorkOrder.setActualFinish(ConvertDate(ActualFinishDate));

// Set Actual Start
myWorkOrder.setActualStart(ConvertDate(ActualStartDate));

// Now save everything
try
{
myWorkOrder.save();
}
catch (Exception err)
{
throw new Exception("Error while saving Work order with ID: " + WorkOrderID.toString() + " - " + err.toString());
}
finally
{
CloseSession();
}
}
1 REPLY
Jeff_443
Occasional Advisor

Re: java.lang.NullPointerException when saving Actual Start for Work Order using web-api

Does anyone have any insight on this? This is still a pressing issue for us.

We are using Service Pack 15. Every time we populate Actual Start Date, we get a NullPointerException.

Thanks,
Jeff
//Add this to "OnDomLoad" event