Servicenow developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi everyone,
I have created a custom table in ServiceNow, but it is not extended from the Task table.
In this table, I have a reference field to the User table (sys_user). My requirement is:
I want the User reference field to show only users who belong to a particular User Group.
The group members should be filtered so that only users in that specific group are visible/selectable.
Since my table is not extended from Task, I cannot use assignment group and assigned to functionality directly.
Could anyone please suggest the best approach to achieve this?
Specifically:
Should I use a Reference qualifier?
If yes, what would be the correct way to filter users based on group membership (sys_user_grmember)?
Is there any recommended best practice for this scenario?
Any guidance or example would be greatly appreciated.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @vodnalar26
Yes, a Reference Qualifier is exactly the right approach here.
javascript:(function(){
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group.name', 'YOUR_GROUP_NAME'); // Replace with your group name
// grp.addQuery('group', 'YOUR_GROUP_SYS_ID'); // Preferred in production
grp.addQuery('user.active', true); // Only active users
grp.query();
var userIds = [];
while(grp.next()){
userIds.push(grp.getValue('user'));
}
if(userIds.length === 0){
return 'sys_id=NULL^EL'; // Returns no results if group is empty
}
return 'sys_idIN' + userIds.join(',');
})()Go to System Definition → Dictionary, find your field, and paste the above into the Reference qual condition field (as a dynamic qualifier).
I hope it helps
Regards
Sumit

