Combine Group Membership for a Qualifier
Overview
This pattern splits a common reference qualifier need into two reusable pieces:
- A classless Script Include,
CheckGroupMembership, that exposes one on-demand function,getGroupMembersRefQual(group_id). Given a group’s sys_id, it queriessys_user_grmemberfor active members of that group and returns a ready-to-usesys_idIN...encoded query string of their user sys_ids. - A Reference Qualifier script — used here on a “Manager” variable in a catalog item - that calls
getGroupMembersRefQual()twice (once per group), then merges and de-duplicates the two result sets before returning a single combinedsys_idIN...string.
Because the membership lookup lives in the Script Include, any other reference qualifier that needs “members of group X” (or “members of group X or Y”) can reuse the same function instead of re-writing the sys_user_grmember query each time.
Problem Statement
A reference field sometimes needs to be scoped to more than one group’s membership. For example, showing both “Approving Managers” and “Non-Approving Managers” in a single Manager picker. Combining two independent group lookups into one qualifier means running each query, merging the results, and removing duplicates (since a user could belong to both groups) before returning the final sys_idIN list.
CheckGroupMembership.js
| |
Note that
group1 and group2 each already start with the sys_idIN prefix, so .split(',') on the first element leaves sys_idIN<firstUserId> intact. The de-duplication and join() treat it like any other array entry, and the final 'sys_idIN' + combinedGroups prepends the prefix a second time. This works out because sys_idINsys_idIN<id>,<id>... still parses fine as the first IN value, but if you reuse this pattern elsewhere, it’s cleaner to strip the sys_idIN prefix before merging.Last updated on