How to select only users of a specific group into a reference field


Description

A customer had the requirement to restrict a field referencing sys_users to only list active users who are members of a specific group.


Release or Environment

All

Instructions

There is a solution based on the configuration of the standard field in the dictionary:
https://<instance>.service-now.com/nav_to.do?uri=sys_dictionary.do?sys_id=9da647c8db55101013e60032ba96195f%26sysparm_view=advanced

It is filtering the sys_user reference list depending on the current value of the group field of the current record using an advance reference qualifier with the expression:

javascript:'sys_idIN'+getIDs(current.group); function getIDs(grp){var m=GlideUserGroup.getMembers(grp);var ids=''; while (m.next()){ids+= (m.user+',');} return ids;}

This approach could be applied to meet the customers requirement to display only active users that belong to a specific group with sys_id=2d6649bbdbb356004ff5f4331f961924

I suggest in your reference field you use an advanced reference qualifier with the following expression:

javascript:'active=true^sys_idIN'+getIDs("2d6649bbdbb356004ff5f4331f961924"); function getIDs(grp){var m=GlideUserGroup.getMembers(grp);var ids=''; while (m.next()){ids+= (m.user+',');} return ids;}