Why has ServiceNow chosen to torture me with JSUtil.notNil and GlideStringUtil.notNil returning different results?

DrewW
Mega Sage
Mega Sage

Recently we started looking at upgrading to Jakarta patch 7.  What we found is in the "Approval - Group" workflow activity was bypassing its approvals because we use a script to look at the groups object and the counts that it returns to make decisions.  Well in Patch 7 and Patch 6a the values in the groups object are all zero.

What we found is that in the "Approval - Group" workflow activity script on line 323 you have this
https://<YOURINSTANCE>.service-now.com/nav_to.do?uri=wf_activity_definition.do?sys_id=354e911f0a0a02...

if (GlideStringUtil.notNil(activity.scratchpad[id]))
    groupRet = this.approvalUtils.getGroupUserApprovalCounts(activity.scratchpad[id]);
else
    groupRet = this.approvalUtils.getUserGroupApprovalCounts(id);

What is happening is that activity.scratchpad[id] is undefined and the GlideStringUtil.notNil is returning true when I'm sure that the ServiceNow developer that wrote the code was expecting it to returned false or just was not thinking based on other code in the script.  I logged an incident and am waiting for support to acknowledge the issue so it gets fixed before I go and fix it so we can upgrade, yay for us.

BUT, what is boggling my mind is that GlideStringUtil.notNil returns true for undefined when JSUtil.notNil returns false.  You can see that with the below code which can be run as a background script. 

var x;
gs.print(x);
gs.print(GlideStringUtil.notNil(x));
gs.print(JSUtil.notNil(x));

Returns
*** Script: undefined
*** Script: true
*** Script: false

There is no documentation for GlideStringUtil that I can find so I’m feeling a little persecuted for being a ServiceNow developer and wondering why are they doing this to me/us, I swear I have done nothing to deserve this.

If I have to beg for consistency I will.  I will even beg for documentation if it will help.

Ok, I’m done ranting, thanks for reading. 🙂

5 REPLIES 5

I see there code workaround has the fix I was going to implement because of the undefined var being passed.