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:07 PM
Hi Brian,
are you using scoping?
I've tested your script using Scoped Script Logging and it works for me:
http://wiki.servicenow.com/index.php?title=Scoped_Script_Logging#gsc.tab=0
Here is my script include (Helsinki release):
var GlideSystemTesting = Class.create();
GlideSystemTesting2.prototype = Object.extendsObject(AbstractAjaxProcessor, {
testingStuff: function(){
gs.info('Am I being ran?');
return 'INC0000055';
},
type: 'GlideSystemTesting'
});
Hope this helps.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2016 11:19 AM
Hello Sergiu,
It looks like I can get logs to show when setting it up this way, however now I'm still running into an issue getting other GlideSystem functions to run, mainly the one I want is the "gs.getProperty" function. It is returning as undefined whenever calling it from a filter, but works fine if I call it directly from a fix script. Do you know of anyway I can access the value of a sys_properties entry within this ajax function as well?
Best regards,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 02:56 AM
Hello bcronrath
To perform this kind of task, I implemented a workaround: a small method determines if gs.getProperty() is available or not, requesting "sys_properties" table if not.
The piece of code:
/**
Return property value, even if gs.getProperty() exists or not.
Parameters and return value are same as gs.getProperty() method.
*/
getProperty: /* String */ function(/* String */ name, /* String */ defaultValue) {
var value = "";
if (JSUtil.nil(defaultValue)) {
defaultValue = "";
}
if (JSUtil.nil(gs.getProperty)) {
//gs.log('need to make a request');
var prop = new GlideRecord('sys_properties');
if (prop.get('name', name)) {
value = prop.value.toString();
} else {
value = defaultValue;
}
} else {
//gs.log('can use original method');
value = gs.getProperty(name, defaultValue);
}
//gs.log('value=' + value);
return value;
},
I put it in a Client callable script include, so I can retrieve property value from server-side and client-side scripts.
I hope it can help someone else.
Regards,
Loí¯c

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2016 05:41 PM
Hi bcronrath,
My first guess would be that since you're making this SI client-callable, it's running as a Client-side script. You cannot use GlideSystem (gs) client-side... this could be the cause of all your woes.
I would check to see if you're generating an error, wrap the whole thing in a try{}/catch{} block and have the catch display any runtime error you might be getting.
Thanks,
-Brian