On load client is not working for normal user like itil, snc_internal

singhr14
Tera Contributor

need to update the existed form ticket variable earlier it one of the variable type is refrence later it got update to single select as the result the value of the variable change to sys_id. 
So now the task is to convert the sys_id into name. it only working for admin not for the normal user

here are the script 

Client script  :  

var gname = g_form.getValue('generic_mailbox_name');
function onLoad() {
   //Type appropriate comment here, and begin script below
   //var gmvalue  = g_form.getValue("generic_mailbox_name");



   var gr = new GlideAjax('test4');
    gr.addParam('sysparm_name','fieldValues');
    gr.addParam('sysparm_agname',gname);
    gr.getXML(UpdateFields);

    //alert("sys_id is   "+ g_form.getValue('generic_mailbox_name'));
   
   
    function UpdateFields(response){
        var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
     
        g_form.setValue('generic_mailbox_name',answer.genericmName);

        //alert(answer.genericmName);
   
       
    }
   
}

Script include : test4
var test4 = Class.create();
test4.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    fieldValues: function(){
    var gmName = this.getParameter('sysparm_agname');
    var gr = new GlideRecord('sys_user');


    gr.addQuery('sys_id',gmName);

    gr.addEncodedQuery('sys_id='+ gmName);
   
    gr.query();
    if(gr.next()){
        var json = new JSON();
                var object= {
                    "genericmName": gr.getValue('name')

    };
        var data = json.encode(object);
        return data;
    }
   
},

    type: 'test4'
});




1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @singhr14 ,

The user you are trying fetch the info for is that account inactive?

ChaitanyaILCR_0-1746812744640.png

OOB there is Query BR on the sys_user table which only shows active records for normal users 

 

check below post of mine

https://www.servicenow.com/community/developer-forum/make-locked-user-accounts-available-from-servic...

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

14 REPLIES 14

singhr14
Tera Contributor

Hi @folusho,

Thank you for your response BUT still it's not working for "snc_internal" / itil role user.

@singhr14 

Can you please be more specific with the error?

At what point is it not working for non-admins?

 

Can you do the following:

1. Put the following alerts in the client script and get the result for both admin and non-admin:

 

     alert("sys_id is: " + g_form.getValue('generic_mailbox_name'));
     alert("answer is: " + answer.genericmName);
   
2. Put the following log in the script include and get the result for both admin and non-admin:
gs.info("Getting Passed Value: " + gmName);
gs.info("Getting Returned Value: " + data);

J Siva
Tera Sage

Hi @singhr14 
Since you mentioned that it's working fine for admins but not for others, it seems to be an ACL issue. When creating a new client-callable script include, you were prompted to provide a role so that users with that role can access the script include. It appears you provided the admin role, which is why it's working only for admins and not for others. To resolve this, go to the script include, open the ACL from the "Access Control" related list, and update the roles to 'snc_internal'.

 

Regards,
Siva

singhr14
Tera Contributor

Hi @J Siva 

Yeah i have update the script include role "snc_internal" but still its not working 

@singhr14 

try this once

Did you add logs and see if script include is getting called or not?

I added this line just before query -> gr.setWorkflow(false);

var test4 = Class.create();
test4.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    fieldValues: function(){
    var gmName = this.getParameter('sysparm_agname');
    var gr = new GlideRecord('sys_user');


    gr.addQuery('sys_id',gmName);

    gr.addEncodedQuery('sys_id='+ gmName);
   gr.setWorkflow(false);
    gr.query();
    if(gr.next()){
        var json = new JSON();
                var object= {
                    "genericmName": gr.getValue('name')

    };
        var data = json.encode(object);
        return data;
    }
   
},

    type: 'test4'
});

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