Workflow error: org.mozilla.javascript.WrappedException: Wrapped org.mozilla.javascript.JavaScriptException: java.lang.NullPointerException
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2021 02:31 PM
Hi all... I am getting the error org.mozilla.javascript.WrappedException: Wrapped org.mozilla.javascript.JavaScriptException: java.lang.NullPointerException (<refname>; line 51) in a "if" workflow script. You will see some gs.addInfoMessage entries, the code runs perfectly fine as an update business rule built on the Change Request table. Other than removing code until I find the culprit, is there any more efficient way to debug? I have seen a similar posting where the error also mentioned a line not contained in the script (i.e. 51). Is this being thrown be down stream ServiceNow code and being passed back up through? Here is the script.
answer=beforeNextCAB();
function beforeNextCAB(){
var startDate = new GlideDateTime(current.start_date);
var nextCAB = new CABLauncher().getNextCABMeeting();
//if next cab start - cab lead time(change property - 90 minutes) > now use this for next CAB end
var nextCABEnd = new CABLauncher().getNextCABMeetingEnd();
//else find next cab after nextCAB and us it's end time for nextCABEnd
var nextCABDate = new GlideDateTime(nextCAB);
var nextCABDateEndAdj = new GlideDateTime(nextCABEnd);
var leadTime = 0;
var grlt = new GlideRecord("u_lead_times");
grlt.addQuery("u_table", "change_request");
grlt.orderBy("u_order");
grlt.query();
while (grlt.next()) {
if (GlideFilter.checkRecord(current, grlt.u_condition, true)) {
leadTime = grlt.u_lead_time;
//gs.addInfoMessage("condition and lead time: " + grlt.u_condition + " : " + leadTime);
break;
}
}
var hours = 60 * 60 * leadTime;
nextCABDateEndAdj.addSeconds(hours);
//gs.addInfoMessage("Next CAB getNextCABMeeting: " + nextCABDate);
//gs.addInfoMessage("Next CAB End getNextCABMeetingEnd: " + nextCABDateEndAdj);
//gs.addInfoMessage("Start Date: " + startDate);
if (startDate.getNumericValue() < nextCABDateEndAdj.getNumericValue()) {
//gs.addInfoMessage("Less than x until next CAB");
return "yes";
} else {
//gs.addInfoMessage("More than x until next CAB");
return "no";
}
}
Thanks - Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2021 01:04 PM
Bahh! I just realized I am still trying to call yet another script include (I love working on legacy code), so I will move that over as a function as well....
Ohh and I created the source variable, which lead me to the other script include. Thanks for catching that...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:58 PM
I finally got it! There was some code using GlideDateTime setTZ. I found I didn't need it anyway so I got rid of it and everything started working. Your mileage may vary. Lessons learned
1) Don't assume your business rule will work as a workflow script
2) Be kind to your future self and clean up your code, comment out functionality that is not longer needed
3) In my case if helped to move just what I needed from custom script includes over as functions in my workflow script. This is only because our custom code was such a mess...
Thanks for all of your guidance Chris!
Tom