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

Arindam Bose
Giga Contributor

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.

5 REPLIES 5

Prateek kumar
Mega Sage

Make it reference to Group Member and use something like this.

find_real_file.png


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

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.

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

AbhishekGardade
Giga Sage

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

Thank you,
Abhishek Gardade