Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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
Solved! Go to Solution.
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
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();
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.
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
there's something else going on. If I comment out everything but the first two lines, I still get the error. I am going to debug some more.
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
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.