- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2025 11:45 AM
OnLoad Client Script:
function onLoad() {
var ga = new GlideAjax('global.TestingClientSide');
ga.addParam('sysparm_name', 'onLoadTest');
ga.getXMLAnswer(callbackFunc);
function callbackFunc(resp) {
alert(resp);
g_form.setValue('description', resp);
}
}
Script Include(Glide AJAX enabled):
var TestingClientSide = Class.create();
TestingClientSide.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoadTest: function() {
return "hello";
},
type: 'TestingClientSide'
});
It is always returning null, I have tried both async, sync methods but is not working either way. Simple thing but dont know why it is not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2025 02:07 AM
I have debugged this, and after trying all the possible solutions I found that everything is working fine.
Just, the function name 'onLoadTest' is causing the issue, because ServiceNow thought it as some OOTB keyword.😑
I have changed the function name to onLodTest/onLoaTest/xyz/etc. all is working fine.
Thank you for all the replies and help. 😄
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2025 11:42 PM
Hi @pranavagarw
Check if the below you have done it
-
It’s in the Global scope (not application-scoped unless you allow cross-scope access).
-
It’s Client Callable (checkbox checked).
-
The function name matches exactly.
Here’s a correct version:
var TestingClientSide = Class.create();
TestingClientSide.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoadTest: function() {
return "hello";
},
type: 'TestingClientSide'
});
--------
Here’s a working onLoad Client Script version:
function onLoad() {
var ga = new GlideAjax('TestingClientSide');
ga.addParam('sysparm_name', 'onLoadTest');
ga.getXMLAnswer(function(response) {
if (response) {
alert(response);
g_form.setValue('description', response);
} else {
alert('No response received');
}
});
}
Notes:
-
Don’t include 'global.' before the Script Include name in GlideAjax ('TestingClientSide' is enough).
-
The callback function must handle the asynchronous response.
-
Ensure there’s no syntax mismatch (e.g., curly braces or missing semicolons).
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2025 12:48 AM
Hi @pranavagarw ,
1. Script Include Must Be Global and Client Callable
Make sure your Script Include is:
- Active
- Client Callable (checkbox must be checked)
- Global (or accessible from the scope you're calling it from)
Correct Script Include:
var TestingClientSide = Class.create();
TestingClientSide.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoadTest: function() {
return "hello";
},
type: 'TestingClientSide'
});Note -
Make sure:
- The name of the Script Include is exactly TestingClientSide
- It is Client Callable
2. Client Script Must Match the Script Include Name
Your client script is mostly correct, but let’s ensure it’s clean:
function onLoad() {
var ga = new GlideAjax('TestingClientSide'); // No 'global.' prefix
ga.addParam('sysparm_name', 'onLoadTest');
ga.getXMLAnswer(function(response) {
var answer = response;
alert(answer);
g_form.setValue('description', answer);
});
}
- Do not prefix 'global.TestingClientSide' unless you're in a scoped app and the Script Include is in the global scope.
- If you're in a scoped app, ensure the Script Include is in the same scope or accessible.
3. Check Scope Compatibility
If you're working in a scoped application, and your Script Include is in the global scope, you must prefix it like this:
var ga = new GlideAjax('global.TestingClientSide');
Debugging Tips:
- Use console.log() instead of alert() for better debugging.
- Check browser console for errors.
- Use gs.info() in the Script Include to verify it's being called.
Please Mark as complete and close the thread if this is helpful.
Thanks,
Rithika.ch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2025 02:07 AM
I have debugged this, and after trying all the possible solutions I found that everything is working fine.
Just, the function name 'onLoadTest' is causing the issue, because ServiceNow thought it as some OOTB keyword.😑
I have changed the function name to onLodTest/onLoaTest/xyz/etc. all is working fine.
Thank you for all the replies and help. 😄
