GlideAjax is returning NULL value

Maxwell3
Kilo Guru

I am using a script include to pull data onto a record producer, the scrip include is supposed to populate data into the Service Portal form if the users have a previous record, but I keep getting a null value in my alert message. I am using an onLoad client script to populate the record producer. It works under my account but it doesn't work if I impersonate or if I sign in as another user.

I've done this many times on the backend but not really on the front end, I feel as if it shouldn't be that different.

 

Script Include:

 

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

getRecords: function() {
        var obj = {};
        var userID = this.getParameter('sysparm_userid');
        var gr = new GlideRecord('table');
        gr.addQuery('opened_for', userID);
        gr.query();
       
        if (gr.next()) {    
        obj.u_eligibility = gr.getValue('u_eligibility');
        obj.u_application = gr.getDisplayValue('u_application');
        obj.u_status = gr.getValue('u_status');
   
        }
        return JSON.stringify(obj);
},
type: 'Utils'
});
 
onLoad CLient Script:
 
function onLoad() {

    var userID = g_form.getValue('opened_for');
    var ga = new GlideAjax('Utils');
        ga.addParam('sysparm_name', 'getRecords');
        ga.addParam('sysparm_userid', userID);
        ga.getXMLAnswer(function(answer){
           
            alert("Answer: "+answer+userID);
            if(answer == "{}"){
         
            g_form.setDisplay('eligibility',false);
            }else{
            var answerObj = JSON.parse(answer);
                g_form.setValue('eligibility', answerObj.u_eligibility);
                g_form.setValue('status', answerObj.u_status);
                g_form.setValue('application', answerObj.u_application);
   
        //Hide submit button
        var x = this.document.getElementsByName('submit');
        x[0].style.visibility = 'hidden';
               
            }
        });
   
       
    }
1 ACCEPTED SOLUTION

Rohit  Singh
Mega Sage

Hi @Maxwell3 ,

 

If it is working for you and not working while you impersonate then check for ACL role which is assigned while submitting the Script Include.

System Security -> Access Control (ACL)
ACL type: Client Callable Script Include

Name is your script include

 

Then look for role if it is admin then your script include will execute for users having admin hence change the role and assign a generic role which all the users will have. Like ITIL etc.

 

If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.

Regards,
Rohit

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Maxwell3 

client callable GlideAjax have ACLs to it.

Did you check if the user satisfies that ACL? Is that user with snc_external role?

is it calling script include? try adding gs.info()

any query business rule is running on that table and blocking? try to use setWorkflow(false)

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

getRecords: function() {
        var obj = {};
        var userID = this.getParameter('sysparm_userid');
		gs.info('userID' + userID);
        var gr = new GlideRecord('table');
        gr.addQuery('opened_for', userID);
		gr.setWorkflow(false);
        gr.query();
       
        if (gr.next()) {    
        obj.u_eligibility = gr.getValue('u_eligibility');
        obj.u_application = gr.getDisplayValue('u_application');
        obj.u_status = gr.getValue('u_status');
   
        }
        return JSON.stringify(obj);
},
type: 'Utils'
});

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

Shree_G
Kilo Sage

Hello @Maxwell3 ,

 

To have the Script Include executed by Non-Admin user and accessible on Portal as well, create an ACL of type " client_callable_script_inclue"  and added a role "snc_external". Reference snippet below.

 

ShirishGhule1_0-1743745700779.png

 


If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.