Workflow error: org.mozilla.javascript.WrappedException: Wrapped org.mozilla.javascript.JavaScriptException: java.lang.NullPointerException

Tom Siegel
Kilo Guru

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

 

11 REPLIES 11

Tom Siegel
Kilo Guru

I think I have tracked the issue down to the calls on the CABLauncher script include. Not sure why it worked in a business rule though...

Tom Siegel
Kilo Guru

After Working with HI on this and not getting a resolution while on a call I decided to take the functions from the Script Include and add them to the workflow script for testing (tested in my business rule first). This resulted in the error "org.mozilla.javascript.WrappedException: Wrapped ReferenceError: "source" is not defined. (answer = beforeNextCAB();"

answer = beforeNextCAB();

function beforeNextCAB() {
var startDate = new GlideDateTime(current.start_date);

//var nextCAB = new CABLauncher().getNextCABMeeting();
var nextCAB = getNextCABMeeting();
gs.log("Tsiegel nextCAB "+nextCAB);

//if next cab start - cab lead time(change property - 90 minutes) > now use this for next CAB end
//var nextCABEnd = new CABLauncher().getNextCABMeetingEnd();
var nextCABEnd = getNextCABMeetingEnd();
gs.log("Tsiegel next cab end: " + nextCABEnd);
//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.log("Tsiegel 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.log("Tsiegel Less than x until next CAB");
return "yes";
} else {
gs,log("Tsiegel More than x until next CAB");
return "no";
}
}
//***********************************************
function getNextCABMeetingEnd() {
var ndt;
try{
//if (dt===undefined)
//ndt=new GlideDateTime();
//else
ndt=new GlideDateTime();
var tz=new TimeZoneUtils(ndt);
tz.setTimeZone(gs.getUser().getTZ());
var gr = new GlideRecord("cab_meeting");
//gr.addQuery("start",">",gs.nowDateTime());
gr.addQuery("end",">",ndt);
gr.orderBy("end");
gr.query();
if(gr.next()){
var cab_end_date=gr.end;
cab_end_date.setTZ(gr.cab_definition.time_zone);
if (this.debug()) gs.log("Next CAB End: "+cab_end_date,source);
return cab_end_date;
}
else{
if (this.debug()) gs.log("no cab meeting results",source);
}
}
catch(ex){
gs.log("Tsiegel Error: "+ex.message,source);
}
}
function getNextCABMeeting() {
var ndt;
try{

ndt=new GlideDateTime();

//ndt=ndt||new GlideDateTime();
var tz=new TimeZoneUtils(ndt);
tz.setTimeZone(gs.getUser().getTZ());
var gr = new GlideRecord("cab_meeting");
//gr.addQuery("start",">",gs.nowDateTime());
gr.addQuery("start",">",ndt);
gr.orderBy("start");
gr.query();
if(gr.next()){
var cab_start_date=gr.start;
cab_start_date.setTZ(gr.cab_definition.time_zone);
if (this.debug()) gs.log("Next CAB: "+cab_start_date,source);
return cab_start_date;
}
else{
if (this.debug()) gs.log("no cab meeting results",source);
}
}
catch(ex){
gs.log("Error: "+ex.message,source);
}

}

Ok, well yeah that's because of all the log statements you have like

gs.log("Error: "+ex.message,source);

One other question, does your script include have an initialize function at the top like

initialize: function() {},

It's there by default in new script includes, but I think I recall having problems calling a script include from a workflow script once, and the issue ended up being that I had removed the initialize function. Even if it does nothing, just make sure you have the empty function skeleton in your script include.

Tom Siegel
Kilo Guru

In my posting above, I have removed the calls to the script include and added the functions I needed to the workflow script....

Right, but your error there is because you're making several gs.log calls that are referencing an undefined "source" object.