ServiceNow advance reference qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 04:16 AM
My Advance reference qualifier for
"Caller field in Incident will show users of only department of logged in user" not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 04:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 04:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 07:52 AM - edited 04-08-2024 08:23 AM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 05:08 AM
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: -
Reference Qualifier: -
Before Adding Reference Qualifier: -
After Adding Reference Qualifier: - As per my Department is IT. [177 Users belongs to IT Department in my case.]
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