How to filter "Assigned To" users based on Assignment Group hierarchy (including child and grandchil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2025 09:34 AM
- I want the "Assigned To" field to display only those users who are members of the selected Assignment Group, its child groups, and its grandchild groups. This means: If a group is selected in the Assignment Group field, The Assigned To field should only list users who belong to that group, As well as users from any child or grandchild groups related to it. How can this be achieved using a reference qualifier or script include in ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2025 11:58 AM
Hi @Nivetha23jay ,
You can do it using Script include and advanced reference qualifier
Script include make it client callable:
var GetGroupMembersRecursive = Class.create();
GetGroupMembersRecursive.prototype = {
initialize: function() {},
getUsersFromGroupAndSubgroups: function(groupId) {
var groupIds = [groupId];
this._getChildGroups(groupId, groupIds, 2); // limit to 2 levels (children + grandchildren)
var userSet = new Set();
var m2m = new GlideRecord('sys_user_grmember');
m2m.addQuery('group', 'IN', groupIds);
m2m.query();
while (m2m.next()) {
userSet.add(m2m.user.toString());
}
return Array.from(userSet); // return as array of sys_ids
},
_getChildGroups: function(parentId, collector, depth) {
if (depth <= 0) return;
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent', parentId);
gr.query();
while (gr.next()) {
collector.push(gr.sys_id.toString());
this._getChildGroups(gr.sys_id.toString(), collector, depth - 1);
}
},
type: 'GetGroupMembersRecursive'
};
Give this in advanced reference qualifier on assigned to field:
javascript:GetGroupMembersRecursive.getUsersFromGroupAndSubgroups(current.assignment_group);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2025 12:08 PM
It is out-of-the-box (OOTB) if I'm not wrong.
Just make sure that the group has a parent assigned — the rest should work as expected with OOTB functionality.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
