ServiceNow: Automatically Set 'Assigned to' When 'Assignment Group' Contains Only One Member

2024.06.08 | Yuki Rea

Sometimes you may have an assignment group in ServiceNow which only contains 1 member. Wouldn't it be nice if we could save an extra step and automatically set the "Assigned to" field to the sole member of the group? This is very easy to do with a business rule advanced script.

Select the desired table to apply the rule to.

If you want this to apply to all records under the "task" table, then choose "task." This will apply to the incident, sctack, incident_task, etc. tables.
If you only want this rule to apply to a specific table, then select that table instead. The "incident" table for example.





Use the following conditions under the "When to run" tab in your business rule.





Paste the following script within the "Advanced" conditions tab.

 1 (function executeRule(current, previous /*null when async*/ ) {
 2     if (current.active == true) {
 3         var grp = new GlideRecord('sys_user_grmember');
 4         grp.addQuery('group', current.assignment_group);
 5         grp.query();
 6         var count = -1;
 7         if (grp.next()) {
 8             count = grp.getRowCount();
 9             if (count == 1) {
10                 current.assigned_to = grp.user.getDisplayValue();
11             }
12         }
13     }
14 })(current, previous);