User Reference field to List members from multiple groups

Ken65
Mega Expert

We have a user reference field and need to be able to list the members from a select list of user groups. Is there a preferred method for doing this? We don;t need to know the group the user was selected from and the user may appear in more than one group. Any help is greatly appreciated.

Thanks

Ken

8 REPLIES 8

Noah Drew
ServiceNow Employee
ServiceNow Employee

Hi Ken!

You would need to implement a Reference Qualifier to specify the users associated with specific groups.

Once this is done, only those users will be available to choose from in your reference field.

This documentation should help you get this set up:

https://docs.servicenow.com/bundle/madrid-platform-administration/page/script/server-scripting/conce...

Hope that helps!

If it did, please mark as Helpful and consider setting this reply as the Correct Answer to the question, thanks!

 

Adrian Ubeda
Mega Sage
Mega Sage

Hi, 

You should query the table sys_user_grmember and then create an array with the user that you are looking for and apply it on the ref_qual of the field. It should something like this:

// this on the ref qualifier of the fields
javascript: new scriptInclude().function(current.group);

// the code inside script Include function
var arrUsers = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', current.group);
grMember.query();

while(grMember.next()) {
  arrUsers.push(grMember.user);
}

return 'sysIdIN' + arraUSers.join();

You can customize the qualifier as you wish with the query in the GR.

If it was helpful, please give some positive feedback.
Thanks, 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Ken65
Mega Expert

Mark and Adrian

 

Thank you for the helpful posts. I need to be able to include sys_user_grmember records from multiple groups. Can I just add querys for each group? Is there a best practice to keep good performance.

 

thanks

Hi, 

If you need to query multiple groups you can add an encodedQuery with the sys_id of the groups that you need, this Ids should be declared as a system_property.

 

If it was helpful, please give positive feedback.

Thanks, 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆