We have a requirement to display the group members of a particular group on a reference field of User table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 08:50 AM
I want to display the name of group members of a particular group to be shown on a reference field to User table. The field's name is "approver ". Only members of a particular group needs to be populated. This is reference field to the User table.Please find the screenshot.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 08:54 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2019 04:06 AM
Hello Prateek,
I have done the same but it is showing the sys_id of the group members not their names. How to display their names ? Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 09:01 AM
Hi Arindam,
So you have a group field; based on that group field only show the group members belonging to those groups in the approver lookup
the reference table for approver should be sys_user which is correct as per your comment I assume
you need to use reference qualifier for this on approver field as below
way to call ref qualifier
javascript: getGroupMembers(current.<groupField>);
script include
function getGroupMembers(groupSysId){
var arr = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();
while(gr.next()){
arr.push(gr.getValue('user'));
}
return 'sys_idIN' + arr.join(',');
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
‎08-20-2019 09:51 AM
Hello Arindam,
1 .You can call script include from advanced reference qualifier. Here is syntax:
javascript:new UserGroup().getMember();
2. Add following script:
var UserGroup = Class.create();
UserGroup.prototype = {
initialize: function() {
},
getMember: function(){
var group = current.assignment_group;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', group);
gr.query();
var members = [];
while(gr.next())
{
members.push(gr.getValue('user').toString());
//gs.info("mem"+members);
}
return 'sys_idIN' + members.toString();
},
type: 'UserGroup'
};
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade