Script Include: Class Based vs Function Based
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 06:41 AM
Hello Colleagues,
I'm relatively new to ServiceNow script includes and I have some questions about them. What I've noticed is that we can create script includes by extending class "AbstractAjaxProcessor" or as a stand alone javascript functions.
The first method looks like this:
var myScriptInclude = Class.create();
myScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myFuncton: () {
var x = this.getParameter( "my_parameter" )
...
return x * 2;
}
type: 'myScriptInclude '
}
On the client we can say:
var myVar = new GlideAjax( "myScriptInclude" );
myVar.addParam( "my_parameter", "PARAMETER" );
myVar.getXML( callback ) // Here we can specify the callback function, which will do something with the asnwer.
The next option is:
function myScriptInclude ( arg ) {
...
return arg * 2;
}
In the workflow activity we can use it by
gs.include( "myScriptInclude " );
with the function we can build our custom reference qualifier for example
javascript:myScriptInclude("some_argument");
This one is pretty powerfull for building custom filters with some advanced logic.
However I don't know if it is possible to call such script (function based) on the client.
So my question is how those two differs (how ServiceNow perceives them) ? Where can I find something about AbstractAjaxProcessor ? And how can I invoke function based script include on the client side (for example in the catalog form) ?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 06:46 AM
Search for GlideAjax to learn more about AbstractAjaxProcessor.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 06:48 AM
Hi,
You'll want to give your functions names because your GlideAjax call needs to send a sysparm_name to call it. See episodes 5, 6 and 33 about that in the TechNow series
also helpful;
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 06:51 AM
You can use a function as a Script Include.
Note that you need to use GlideAjax and AbstractAjaxProcessor to invoke a script from the client side.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 06:58 AM
Sorry, I missed the very last part about invoking the classless script include from the AbstractAjaxProcessor. yes, this is entirely possible. Put your server side logic in the functionless/classless script include and you can call it form the AbstractAjaxProcessor one.
sabell2012 did an Ask the Expert session on including a script include in a script include like this, but I cannot seem to find it at the moment.