Skip to main content
11-Garnet
September 5, 2017
Solved

workflow expression code - add an int to a timestamp

  • September 5, 2017
  • 2 replies
  • 6053 views

I would like to be able to do the following: 

On a document have a date IBA and an Int IBA. 

within the workflow, use an expression to add the integer (number of days) to the datestamp to get a new datestamp that I can then write back to another IBA in the doc. 

My code checks out syntactically but when I run the WF I get a java.nullpointer.expression.

 

the code is: 

 

wt.doc.WTDocument theDocument =((wt.doc.WTDocument) primaryBusinessObject);

com.ptc.core.lwc.server.PersistableAdapter obj =new com.ptc.core.lwc.server.PersistableAdapter(theDocument,null,null,null);

obj.load("AdditionalDays","resubmitDate","DateDue");

wfAdditionalDays= obj.get("AdditionalDays").toString();
wfresubmitDate= obj.get("ResubmitDate").toString();
wfDateDue= obj.get("DateDue").toString();

// convert the Due Date off the Document unto a java.sql.TimeStamp
java.sql.Timestamp wfDueDate2 = java.sql.Timestamp.valueOf(wfDateDue);

//Convert Additional days to int
odays=java.lang.Integer.parseInt(wfAdditionalDays);

 

java.time.Instant next600Sec =wfDueDate2 .toInstant().plusSeconds(odays*24*3600);
finalTS2= java.sql.Timestamp.from(next600Sec);

 

Any ideas would be greatly appreciated

Best answer by BineshKumar1

Adding debug statements is the right way to go.

Also If you are using int variables, please assign a default value(like 0 or something), I have seen this causing null pointer exception

2 replies

1-Visitor
September 5, 2017

As a good coding practice make sure, what you retrieve is not null before you convert them to string. What if those attributes have null value or if the attribute internal name is incorrect?

wfAdditionalDays= obj.get("AdditionalDays").toString();
wfresubmitDate= obj.get("ResubmitDate").toString();
wfDateDue= obj.get("DateDue").toString();

mduffy-211-GarnetAuthor
11-Garnet
September 7, 2017

Since the variables are retreived from a document IBA, I am able to make the IBA required to ensure that it's not null. 

I agree it's probably a good idea to check for null values, but right now I can't get the code to work with variables I know are correct.

 

1-Visitor
September 7, 2017

Could you add a some print statements to see the value retrieved and calculated? I have never used Timestamp.valueof to convers to timestamp, I have always used simpledateformat. I am not sure whether this is the problem. But adding some printstatements will defintely help you narrow down the issue

15-Moonstone
September 6, 2017

I agree with Binesh.  I imagine at least one of those IBAs are null.  Add some println statements to see where exactly you're getting the error.