- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2016 08:47 AM
I'm trying to create a reference qualifier or script that will allow me to filter out users in the sys_user table by the group membership related list. So if they belong to a specific group, remove them from the available options in the reference field. I see its easy to do it by role but I can't seem to do it by group.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2016 01:59 AM
Here is a description of how to script reference qualifiers, just use script include instead of business rule:
Reference Qualifiers - ServiceNow Wiki
Okay, so to show the full example, this is how it might look.
Script include:
var UserFilterUtils = Class.create();
UserFilterUtils.prototype = {
initialize: function() {},
filterByGroup: function(group_id) {
//Will show only users who are members of the specified group
var found_users = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", group_id);
gr.addNotNullQuery("user");
gr.query();
while (gr.next()) {
found_users.push(gr.user.sys_id.toString());
}
var ref_qual = "sys_idIN" + found_users.join(",");
return ref_qual;
},
filterOutByGroup: function(group_id) {
//Will remove users of the specified group from the list
var found_users = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", group_id);
gr.addNotNullQuery("user");
gr.query();
while (gr.next()) {
found_users.push(gr.user.sys_id.toString());
}
var ref_qual = "sys_idNOT IN" + found_users.join(",");
return ref_qual;
},
type: 'UserFilterUtils'
};
Reference qualifier on the user reference field:
javascript:(new UserFilterUtils()).filterOutByGroup("group_sys_id");
Or if you need to filter by the group that is selected on the form:
javascript:(new UserFilterUtils()).filterOutByGroup(current.field_on_the_form);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 02:24 PM
Thank you Kyryl!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2018 04:46 PM
Thanks so much, I've been trying for hours to figure out how to do this, and this worked perfectly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 04:13 AM
Hi kyryl ,
I have one requirement, I have one field called "user" which is reference field and there are two users belongs to one group(GLOBAL_FINANACVE). For one user we need to show only 40 users and for another we need to show all users. for that i wrote reference Qualifier but it is not working