- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 05:49 PM
Hello,
I'm barely new to Reference Qualifiers and don't know if there's a way to filter the users table and only show the users that have the role "business_partner"
This is what I found when I searched for something:
javascript:"sys_idIN"+getRoledUsers("itil_admin").join(",")
But I really don't know how it works, that qualifier brings me all users that have at least one role from parent role to child roles
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 06:35 PM
getRoledUsers is an OOTB script (see Business Rule getRoledUsers)
// Return an array of sys_ids of the users that have at least one role
// optional parameters allow the exclusion (NOT IN) of some roles or
// look for specific roles (IN)
//
// optional: queryCondition - 'IN' or 'NOT IN'
// optional: roleList - a comma separated list of role names
//
function getRoledUsers(queryCondition, roleList) {
var roleListIds;
if (queryCondition && roleList) {
roleListIds = getRoleListIds(roleList);
}
var users = {};
var gr = new GlideRecord('sys_user_has_role');
if (roleListIds) {
gr.addQuery('role', queryCondition, roleListIds);
}
gr.query();
while (gr.next()) {
users[gr.user.toString()] = true;
}
var ids = [];
for (var id in users)
ids.push(id);
return ids;
}
So, the syntax your are looking for is
javascript:'sys_idIN' + getRoledUsers('IN','itil_admin').join(",");
No need for custom code
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 06:11 PM
Would you like to do this.
Script Include:
Name: RoleUtilities
Script:
var RoleUtilities = Class.create();
RoleUtilities.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRoledUsers : function(){
var arr=[];
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('role.name','itil_admin');
gr.query();
while(gr.next()){
arr.push(gr.user);
}
return 'sys_idIN'+arr;
},
type: 'RoleUtilities'
});
Reference Qualifier:
javascript: new RoleUtilities().getRoledUsers();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2017 08:11 AM
This code will help me in the future, thanks a lot! (:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 06:35 PM
getRoledUsers is an OOTB script (see Business Rule getRoledUsers)
// Return an array of sys_ids of the users that have at least one role
// optional parameters allow the exclusion (NOT IN) of some roles or
// look for specific roles (IN)
//
// optional: queryCondition - 'IN' or 'NOT IN'
// optional: roleList - a comma separated list of role names
//
function getRoledUsers(queryCondition, roleList) {
var roleListIds;
if (queryCondition && roleList) {
roleListIds = getRoleListIds(roleList);
}
var users = {};
var gr = new GlideRecord('sys_user_has_role');
if (roleListIds) {
gr.addQuery('role', queryCondition, roleListIds);
}
gr.query();
while (gr.next()) {
users[gr.user.toString()] = true;
}
var ids = [];
for (var id in users)
ids.push(id);
return ids;
}
So, the syntax your are looking for is
javascript:'sys_idIN' + getRoledUsers('IN','itil_admin').join(",");
No need for custom code
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2017 08:12 AM
This is exactly what I needed for this requirement.
Would it be too much if I asked you what difference does it make by adding the "IN" into the script?