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

Brad Bowman
Kilo Patron
Kilo Patron

The department field on the sys_user table is a reference, so it needs the sys_id.  Try logged_user.getValue('department') instead of getDisplayValue.  You can also add some log lines to the script to confirm it is getting called, and if the GlideRecord is returning any records.

hello @Brad Bowman  ,

 

thanks for replying

 

But, still it is not working

Hi, @shivani18 

 

Replace your addEncodedQuery() with addQuery();

 

Also, you could try this approach, although it may not be the most optimal one.

 

Also, there's no need to make it callable from the client side.

 

 

 

var gr = new GlideRecord('sys_user');
gr.get(gs.getUser().getID());
var depart = gr.getValue('department');

var gr2 = new GlideRecord('sys_user');
gr2.get('department', depart)

var callerUser =[]

while(gr2.next()){
callerUser.push(gr2.getValue('sys_id'))
}

return 'sys_idIN' + callerUser;

 

 

 

AakashG2703
Mega Guru

Hi @shivani18,

Hope you are doing well.

 

Proposed Solution

In order to achieve this task, I personally tried it on my "Personal Developer Instance" so that you can get the solution as soon as possible. For this, you just need to change your "Script Include" from "Non-Client Callable" to "Client Callable" by marking the checkbox of Client Callable Field in Script Include as "Checked" to get your query resolved. Attaching my Script and some snapshots of the outputs for your reference mentioned below: -

var PopulateUsersBasedonDepartment = Class.create();
PopulateUsersBasedonDepartment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    loggedInUser: function() {
        var arr = [];
        var gr = new GlideRecord("sys_user");
        gr.addQuery("sys_id", gs.getUserID());
        gr.query();
        if (gr.next()) {
            var gr2 = new GlideRecord("sys_user");
            gr2.addQuery("department", gr.department);
            gr2.query();
            while (gr2.next()) {
                arr.push(gr2.sys_id.toString());
            }
        }
        return "sys_idIN" + arr;
    },
    type: 'PopulateUsersBasedonDepartment'
});

 

Script Include: -

AakashG2703_0-1712577806054.png

 

Reference Qualifier: -

AakashG2703_2-1712578011795.png


Before Adding Reference Qualifier: -

AakashG2703_3-1712578052668.png

 

After Adding Reference Qualifier: - As per my Department is IT. [177 Users belongs to IT Department in my case.]

AakashG2703_1-1712577955858.png

 

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

 

Thanks ‌‌:)

Aakash Garg

ServiceNow Developer