Cannot execute Script Include function from catalog client script

Suyong
Giga Expert

Hi Community,

 

When logging in to the portal as an external user and displaying the catalog item screen, the script include function cannot be called from the onLoad script that is executed.

However, if you view the relevant screen from the portal as admin user, the script include function will be executed correctly.

What is the cause of the Script Include function call not working when the screen is displayed as an external user?

I'm new to ServiceNow and JavaScript, so I expect easy-to-understand comments.
Thanks in advance,

 

****** Catalog Client Scripts *****
function onLoad() {
    var userid = g_user.userID;
    var ga = new GlideAjax('CmnUtil');
    ga.addParam('sysparm_name', 'logtest');
    ga.addParam('sysparm_foo', 'foofoo');
    ga.getXMLAnswer(function(answer) {
        if(answer) {
            console.log('--- answer is enable ---' + answer);
        } else {
            console.log('--- answer is disable ---');
        }
    });
}
*****  Script Include *****
var CmnUtil = Class.create();
CmnUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    logtest: function() {
        var str = this.getParameter(sysparm_foo);
            gs.info('**** CmnUtil - logtest *****' + str);
            return "logtest success!!!!";
    },
    type: 'CmnUtil'
});

**** Web browser Console ( execute by external user ) ****

Suyong_2-1739858749866.png

**** Web browser Console ( execute by admin user ) ****

Suyong_3-1739858790871.png


***** Extenal user *****

Suyong_0-1739858442989.png

 

***** admin user *****

Suyong_1-1739858667811.png

 



 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Suyong 

if it's snc_external user then add this function isPublic in your script include and it will be able to call

var CmnUtil = Class.create();
CmnUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    logtest: function() {
        var str = this.getParameter(sysparm_foo);
            gs.info('**** CmnUtil - logtest *****' + str);
            return "logtest success!!!!";
    },

isPublic: function() {
        return true;
    },
    type: 'CmnUtil'
});

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Vishwa Pandya19
Mega Sage

Hey @Suyong,

 

Check the ACL's on the script include. See whether it includes snc_external role to it.

 

If my answer has helped you in any way please mark it as correct or helpful.

Thank you for your response!

I solved the problem by setting the Requires role correctly in the ACL of the script include


Thank you very much.

Ankur Bawiskar
Tera Patron
Tera Patron

@Suyong 

if it's snc_external user then add this function isPublic in your script include and it will be able to call

var CmnUtil = Class.create();
CmnUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    logtest: function() {
        var str = this.getParameter(sysparm_foo);
            gs.info('**** CmnUtil - logtest *****' + str);
            return "logtest success!!!!";
    },

isPublic: function() {
        return true;
    },
    type: 'CmnUtil'
});

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thanks for the response!

I see, you check the accessibility of the script include in the function - isPublic.


I will refer to it!
Regards