GlideAjax: Not able to access function inside script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2015 01:14 PM
I have created a custom application and i am trying to do a GlideAjax, though onSubmit client script , to access a script include within the same scope. I put a debug statement each inside the 'initialize' and 'testfunction' which i am calling in my client script. I found that on execution of the script only the debug statement inside initialize is reflecting in the System Logs. Is the 'testfunction' not getting called at all? The value in the 'answer' variable is also null after execution.
Following is my script include:
Corresponding Client Script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2015 12:45 AM
Hi Jivan,
I am not able to reproduce the issue you mentioned at my end. I've done the setup on the below demo instance where it is working fine. Can you please check the same and let me know if you have any questions.
Demo URL : https://demo007.service-now.com/login.do
UserName : admin
Password : admin
Steps for testing : Go to the module Demo from the left navigator and click on demo test. You will see the popup "Hello". Please refer the client script and Script Include "DemoNowUtility".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2015 01:10 AM
Hi Pradeep,
I tested the setup on demo007, indeed its working correctly. The only differences i see is that you used onLoad whereas i am using onSubmit; and there is no initialize function in your setup. I am wondeirng whether the issue in my setup is because of that, or my instance is caising the problems; any thoughts?
I will continue trying to figure this out meanwhile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2015 07:17 AM
I was able to resolve the issues with the following workaround:
1. removed 'initialize' method: on removing initialize, i was able to call all given functions in the script include from my client script.
2. removed private functions: private functions were not getting called from the non-private functions, so i modified them to do stand-alone processing instead of calling any private function.
I am not sure whether this is expected behaviour, but this is how GLideAjax seems to be working in scoped applications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2015 01:37 PM
Hi Jivanjot,
Blergh. I totally glossed over that initialize method.
If you override AbstractAjaxProcessor's initialize method with one of your own, you need to call the original initialize method in yours, or you want have an automatic response XML object, access to passed-in parameters, etc.
This is, in fact, expected behavior. When you create a client-callable Script Include and it automatically populates the script box with your template, it does not include an initialize method. That is on purpose- it's a PITA to write a good initialize method for the extended class which also properly calls the original. However, if you take a look at the client-callable script includes on your instance you'll see some of them do provide an initialize method, and also call AbstractAjaxProcessor's method. You'll also see that it's ugly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 06:27 AM
I just read this post from 5 years ago and to me it only worked when I removed initialize method (running Orlando version in the "future").