Why can't GlideSystem be called from scripts used by filters?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2016 02:23 PM
I'm noticing trying to do gs.<anything> is not working when using them in script includes for use in filter functionality. This is making it so I can't call system properties or do logging or other useful things that GlideSystem allows.
Steps to reproduce:
1.) Create a new script included called testingStuff. Make it Client Callable, in the Global Appication, and accessible from All application scopes.
function testingStuff(){
gs.log('Am I being ran?');
return 'INC0000001';
}
Replace INC0000001 with a real incident from your system to use for testing.
2.) Now create a fix script called "test normal call", have it only Run Once, and just have this as the script:
gs.print(testingStuff());
Run it, and see that it logs fine.
3.) Now go to any incident view, click on the filters and have it be like the following:
That's javascript:testingStuff() in the textbox there.
Run it and see that it runs the part of the code fine that returns the incident number, because now your test incident will show up as your filtered record. However, check the System Logs -> Script Log Statements and see this time that it didn't record any logs. You can also add other GlideSystem functions to your function to see that none of the others will run either, such as gs.getProperty
What is going on here? How can we go about getting GlideSystem functionality to work for filtering?
Best regards,
Brian
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2016 05:46 PM
As a follow-up, in the scenario of needing to use gs methods client-side (e.g., gs.getProperty()), I've found a valid workaround to be using an on Display business rule to call the gs functionality and store the value on the scratchpad (which you can then access from the client-side). See here:
Scripting in Business Rules - ServiceNow Wiki
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2016 11:20 AM
Thanks Brian,
I will try this out!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2016 02:02 PM
Hmm I seem to be getting a "g_scratchpad" is not defined when attempting to pull the value. It is thrown from the script include and not the business rule, could this be an issue with the way the order of operations are executing when trying to call the function from a filter search? I think what's happening is the business rule for display (I also tried a before and after query business rule but to no avail) is being executed after the function is attempted to be called.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2016 02:06 PM
Actually I stand corrected, it's being thrown from the business rule as well when trying a before query. In the examples I didn't see it being declared or anything of that sort, is there anything I need to do as a prereq to get the g_scratchpad to be recognized properly?