Cannot call script includes from scoped applications

Ulf Cederholm
Tera Expert

I have a simple script include that I use as test. I'm trying to call the script from a client script in any of our scoped applications, But no matter what I try no log entry is generated in 'Script Log Statements'. So it look like the script include isn't called at all. Everything works just fine though from any global client scripts.

As far as I know it should work? What the obvious thing I'm missing? Anyone have any ideas?

Client script code I'm testing with:

var ga = new GlideAjax('LUCallableFromScopedAppTest');
ga.addParam("sysparm_name", "checkIfLoggedInUserHasRoleITIL");
ga.getXML(getResponse);
function getResponse(response) {
    //Nothing
}

Script Include:

var LUCallableFromScopedAppTest = Class.create();
LUCallableFromScopedAppTest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkIfLoggedInUserHasRoleITIL: function() {
        gs.log('UlfC [LUCallableFromScopedAppTest] [checkIfLoggedInUserHasRoleITIL] [Script Include] [' + gs.getUserID() + ' has ITIL role <IS> ' + gs.hasRole('itil') + ']');
        return gs.hasRole('itil');
    },
    
    type: 'LUCallableFromScopedAppTest'
});

find_real_file.png

1 ACCEPTED SOLUTION

Ulf Cederholm
Tera Expert

I may have solved the issue. As mentioned in the article regarding 'cross scope access privilege' you should go to 'Application Restricted Caller Access Privileges' and find any requests there from the scoped app to access global. However I could not find any. But, I could find them in 'Application Cross-Scope Access'.

 

Here I could change the custom application entry and the field 'Runtime Access Tracking'. Default seems to be 'Enforcing' and changing this to '--None--' (and perhaps 'Tracking' as well) grants the scoped app access to the script include in glodal (using global.<script_include>). I'll have to check some more, but at least my test scripts all work now.

View solution in original post

6 REPLIES 6

palanikumar
Giga Sage

Hi,

Are you calling client script on change or onload? add alert message and check whether it is getting called

Thank you,
Palani

Mahendra RC
Mega Sage

Hello,

Please check with below change

var ga = new GlideAjax('global.LUCallableFromScopedAppTest');
ga.addParam("sysparm_name", "checkIfLoggedInUserHasRoleITIL");
ga.getXML(getResponse);
function getResponse(response) {
    //Nothing
}

Thanks

Also in your gs.log there is I think some issue:

gs.log('UlfC [LUCallableFromScopedAppTest] [checkIfLoggedInUserHasRoleITIL] [Script Include] [' + gs.getUserID() + ' has ITIL role <IS> ' + gs.hasRole('itil') + ']');

The itil in inside ' single quote not sure if that can cause an issue

Please check once with below log updated using " double quotes

gs.log("UlfC [LUCallableFromScopedAppTest] [checkIfLoggedInUserHasRoleITIL] [Script Include] [" + gs.getUserID() + " has ITIL role <IS> " + gs.hasRole('itil') + "]");

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

 

 

Pavankumar_1
Mega Patron

Hi,

Can you try different logging methods like gs.info instead of gs.log

It will work.

 

Thanks,

Pavankumar

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar