Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

OnLoad Client Script is not working with GlideAjax

pranavagarw
Tera Expert

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.

1 ACCEPTED SOLUTION

pranavagarw
Tera Expert

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. 😄

View solution in original post

7 REPLIES 7

GlideFather
Tera Patron

Hi @pranavagarw,

 

if it is in global scope, you might not need the global prefix in calling the script include. also you combine single and double quotes. none of it might not be the culprit, but cost you nothing to try.

 

Have you tried to log the values?

_____
This reply is 100 % GlideFather and 0 % AI

AndersBGS
Tera Patron
Tera Patron

Hi @pranavagarw ,

 

Have you ensured correct configuration of the script include in the record itself?

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Chaitanya ILCR
Mega Patron

Hi @pranavagarw ,

Things to check

1. make sure client callable/GlideAjax Enabled is checked

2. if you client script is in different scope make sure the script include is accessible from all application scopes

ChaitanyaILCR_0-1761632441544.png

 

3. also check if there is any ACL on the script include and the user has access to call the ACL

put the filter name contains your script include name operation=execute and type = client_callable_script_include

 

if you find any acl check if the users have relevant role to call the script include

 

if there are no acls 1st 2 check should fix the issue

 

ChaitanyaILCR_1-1761632588521.png

 

above 3 checks should fix the issue

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@pranavagarw 

both client script and script include are in same scope?

share screenshots for both the scripts

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader