- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 11:38 PM
Can anyone please explain me how to filter the users from only one group in reference fields reference to sys_user table.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 11:53 PM
Hi,
you need to use advanced reference qualifier on that user reference field
javascript: 'sys_idIN' + new GetGroupMembers().getUsers();
Script include
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
initialize: function() {
},
getUsers: function(){
var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group.name", "ABC Group");
gr.query();
while(gr.next()) {
arr.push(gr.getValue('user'));
}
return arr.toString();
},
type: 'GetGroupMembers'
};
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 09:52 AM
Can this same script include be used for referencing multiple groups instead of just one?? If so, how??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 09:50 PM
@Brandon R1 Yes we can use it for multiple group.
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
initialize: function() {
},
getUsers: function(){
var groupIDs = ['sys_id1','sys_id2','sys_id3']; // save comma separated list of groups sys_id
var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group.sys_id","IN", groupIDs.toString()); // and small change to this line
gr.query();
while(gr.next()) {
arr.push(gr.getValue('user'));
}
return arr.toString();
},
type: 'GetGroupMembers'
};
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2025 07:24 AM
thanks, it worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2025 07:28 PM
Hi Ankur,
I have same scenario like this but in my case i am using
Script Include, On change where if I select a group in a variable
the variable 'list member' will only display member based on what the value in the selected group.
i try to pass the value from onchange to script include like changing "ABC Group".
Any thoughts how to apply this in onchange
gr.addQuery("group.name", "ABC Group");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2021 02:16 AM
Using this script include method now requires users in the portal to have a license to view the results.
See KB0720034
This changed in June 2021.
If you require users without a license to view the results, you will need to edit the ACL, or re write the query on the variable
