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

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

Hi @Maxwell3 ,

Hope you are doing good.

 

Did you check my response above.

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

 

Regards,
Rohit

Thank you Rohit for your answer. It was set to 'Admin', I set it to a more generic role.

@Maxwell3 Glad that I was able to help you. Request you to also hit thumbs on my response.

 

Regards,

Rohit