Get Group Members Function [Business Rule]
Import
·
Mar 27, 2020
·
article
Remember that you can create a global function that can be called whenever you need in the back-end.
In this particular case the members of a group must be pulled in order to filter a User reference field in the form by a Group reference field in the same form. This is a typical example of Assignment Group and Assigned To inter-dependency. When you choose a group in the Assignment Group field, the Assigned To field should only display user members of the group selected.
With a simple global business rule you can filter the Assigned To field easily:
function getGroupMembers(fieldName) {
var groupValue = current.getValue(fieldName);
if (gs.nil(groupValue)) {
return "active=true^EQ";
}
var member = new GlideRecord("sys_user_grmember");
member.addQuery("group", groupValue);
member.query();
var list = [];
while (member.next()) {
list.push(member.getValue("user"));
}
return "sys_idIN" + list.toString();
}
Here an example:
Easy, clean and practical in the data dictionary of the Assigned To field:
View original source
https://www.servicenow.com/community/itsm-articles/get-group-members-function-business-rule/ta-p/2311201