GlideAjax is not executing Script Include method across scope

AlwinJebakY
Tera Expert

I'm facing an issue while calling a Script Include from a Client Script using Glide Ajax. 

My Client Script is in the Global Scope 
The Script Include is in the Customer Service Scope
      Accessible from is already set to All Application Scope
      Script Include is marked Client Callable = true 

The GlideAjax request is visible, Script Include is getting triggered
But the function inside the Script Include is not executing

I have already verified the following
       Script Include is marked Client Callable = true 
       Script Include is accessible from all application scopes
       In Client Script Correct Script Include name and function name are used
       No Console errors
       GlideAjax call is firing correctly 

Still the Script Include does not executed.

Is there anything else required to call a Script Include from Global Scope When it is created under Customer Service  Scope ? 




10 REPLIES 10

@Ankur Bawiskar 
Still now that function is not executed 

@AlwinJebakY 

any reason client script and script include are in different scope?

why not keep them both in same scope? then it will work for sure.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar 
If we will create Client Script and Server Script in same scope
Then why they will provide Accessible from All Application Scope option.  

KelvinY2025
Tera Contributor

I discovered this problem last week and asked for a few days without any breakthrough. At one point, I suspected it was my own problem. 11 months ago, there was a YouTube video that said it could be done, but it didn't work at all. I asked AI for various solutions, but none of them worked. Servicenow is too closed. It feels like this won't work, that won't work. People who can't code won't use it, and people who can code won't use it either.

Sarthak Kashyap
Mega Sage

Hi @AlwinJebakY ,

 

I tried your problem in my PDI and it works for me 

 

Please check solution below 

 

Client script which is onChange on caller field

SarthakKashyap_0-1764146908030.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

	alert("Called SI");

	var ga = new GlideAjax('sn_hr_core.myScriptIncNew'); 
    ga.addParam('sysparm_name', 'callFunc'); 
    ga.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		alert("Ans = " + answer);
    });

}

 

Script Inc

SarthakKashyap_1-1764146958080.png

var myScriptIncNew = Class.create();
myScriptIncNew.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

	callFunc: function(){
		return "Called SI in Different Scope"
	},

    type: 'myScriptIncNew'
});

 

 

Result

SarthakKashyap_2-1764147008060.png

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak