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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 06:18 AM
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. 🙂
- Labels:
-
Scripting and Coding
- 3,103 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 09:01 AM
GlideStringUtil is a java class and JSUtil is a Javascript class.
I'm guessing GlideStringUtil is a little out of his depth when dealing with javascript objects.
- Tim.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 10:23 AM
I'm guessing that also, but that does not mean that they cannot make an effort to have it return consistently with other library's.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 11:51 AM
Perhaps it was a mistake exposing StringUtil to Javascript in the first place.
JSUtil is the right tool for the job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 09:07 AM
I think your having the same issue we faced with approvals after a patch upgrade.
PRB1244065 - When using an Approval - Group activity with the Wait For Condition based on script option, the Approval - Group activity may get stuck and not progress the workflow. https://hi.service-now.com/kb_view.do?sysparm_article=KB0657504