ServiceNow advance reference qualifier

shivani18
Tera Contributor

My Advance reference qualifier for 

"Caller field in Incident will show users of only department of logged in user" not working

shivani18_0-1712574924748.png

shivani18_1-1712574992410.png

 

 

9 REPLIES 9

Hello @AakashG2703 ,

 

Thank you for replying

 

i made the script include client callable

but still it is not working.

 

is there any issue in my script?

 

 

Hi @shivani18,

 

Request you to try to create a new "Script Include" as "Client Callable". Pls do not modify an existing one. There is a reason that I personally seen many times behind to not to modify an "existing Script Include" as it does not get updated as per the "Checkbox Selection or De-Selection".

 

If you find any information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.

 

Thanks ‌‌:)

Aakash Garg

ServiceNow Developer

hello @AakashG2703 ,

 

no its still not working. 

may be there is some issue in my script's query

can you please check once again

Hi @shivani18,

Hope you are doing well.

 

Proposed Solution

I tried again to rectify your issue on my "Personal Developer Instance" so that you can get the solution as soon as possible. As a solution, I started looking into your script and implemented it on my PDI and started debugging it by adding lot of "System Logs" and here are some findings that I found mentioned below: -

  1. Replace getDisplayValue() --> getValue() in Line 8.
  2. Replace addEncodedQuery() --> addQuery() in Line 9.

Attaching Screenshot for the reference: -

AakashG2703_0-1712601087355.png

 

New Script: -

var PopulateUsersBasedonDepartment = Class.create();
PopulateUsersBasedonDepartment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    loggedInUser: function() {
        var gr = new GlideRecord('sys_user');
        var logged_user = gs.getUser().getRecord();
        var depart = logged_user.getValue('department');
        gr.addQuery('department', depart);
        gr.query();
        var callerUser = [];
        while (gr.next()) {
            callerUser.push(gr.getValue('sys_id'));
        }
        return 'sys_idIN' + callerUser;
    },
    type: 'PopulateUsersBasedonDepartment'
});

 

It seems to be working fine for me. Hope this time your issue gets resolved.

 

If you find any of the shared information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.

 

Thanks ‌‌:)

Aakash Garg

ServiceNow Developer

Subhashis Ratna
Tera Guru

Hi @shivani18 

I have updated Code for SI ....

 

 

//Logic - 1 

    loggedInUser: function() {
    var loggedUserRec = gs.getUser().getRecord();
    var depart = loggedUserRec.getValue('department');
    var callerUser = [];
    var grRec = new GlideRecord('sys_user');
    grRec.addQuery('department', depart);
    grRec.query();
    while (grRec.next()) {
        callerUser.push(grRec.getValue('sys_id'));
    }
    return 'sys_idIN' + callerUser.join(',');
},


Logic - 2 


    loggedInUser: function() {
        var depart = gs.getUser().getDepartment();

        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('department', depart);
        userGr.query();
        var callerUser = [];
        while (userGr.next()) {
            callerUser.push(userGr.getValue('sys_id'));
        }
        
        return callerUser;
    },

 


SS - 1

SubhashisRatna_0-1712755627867.png

 

 


If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna