Round Robin Assignment Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 02:43 AM
How can I create an assignment rule on the task and incident table both so that the rule can assign incidents and the tasks to the a particular group in Servicenow.
Also, the assignment of the tickets (both task and the incident) should follow a Round Robin style of assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2021 03:50 PM
That's good to know:)
I've modifed the code to handle the scenario you describe, to treat each group separately. We can still do it in a single business rule and with a single property:
(function executeRule(current, previous /*null when async*/) {
var GRPSYS_ID = '21cef0862f022010d345b6a62799b61d,7965715edba02300c895d6aa489619dd'; //Put the sys_id of the assignment group (or groups comma separated) here. Or set this in a system property and grab it here.
var thisGroup = current.getValue('assignment_group');
if (!GRPSYS_ID.includes(thisGroup)) //Exit if thisGroup is not in our list GRPSYS_ID.
return;
var assignJSON = gs.getProperty("rr.last_assigned_to") || ''; //Get the sys_ids of the users most recently assigned to, per group, by this rule.
var assignObj = (assignJSON) ? JSON.parse(assignJSON) : {};
var lstAssigned = assignObj[thisGroup] || '';
//Make an array of all users in the assignment group, ordered alphabetically by name:
var userList = [];
var userHasGroup = new GlideRecord('sys_user_grmember');
userHasGroup.addQuery('user.active', true);
userHasGroup.addQuery('group', thisGroup);
userHasGroup.orderBy('user.name');
userHasGroup.query();
while (userHasGroup.next())
userList.push(userHasGroup.getValue('user'));
var nextUserIndex = userList.indexOf(lstAssigned) + 1;
if (nextUserIndex == userList.length)
nextUserIndex = 0;
var nextUser = userList[nextUserIndex];
current.assigned_to = nextUser;
assignObj[thisGroup] = nextUser;
assignJSON = JSON.stringify(assignObj);
gs.setProperty("rr.last_assigned_to", assignJSON); //Update the property with the sys_ids of the users most recently assigned to, per group, by this rule.
})(current, previous);
The difference is that we now store a JSON object in the property, with the group sys_id as the keys, and latest assignees as the values. When we create the array of users, we look at only the newly assigned group, and then update the corresponding value in the JSON.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2021 06:16 AM
Amazing! Thank you, again! My users have thrown one more curveball at me, though: apparently, they don't actually want Round Robin to include all members of their assignment group. Each group has exceptions that they do not want included in the round robin. Have you encountered this scenario?
Is it maybe possible to add a yes/no field named "Round Robin" to the sys_user table and key off this in your script? Some other method? I considered round robin groups, but I'm concerned about user error in selecting from multiple, similar groups and also about potential ACL issues as we often tie ACLs to role and then to group in order to assign them...
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2021 09:45 AM
Hi,
yes adding a yes/no to sys_user is probably the best way to go, and easiest to maintain / update. So you would then just need one additional condition in the script when querying the sys_user_grmember table, something like:
userHasGroup.addQuery('user.u_roundrobin', true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2021 10:10 AM
This works perfectly. Thank you so, so much for helping me with it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 01:18 PM
So, I seem to have broken something... This script is no longer setting the assigned to:
(function executeRule(current, previous /*null when async*/) {
var GRPSYS_ID = 'f5c8e951db3e4f0000f438ff9d961932, c6c8e951db3e4f0000f438ff9d961964'; //Put the sys_id of the assignment group (or groups comma separated) here. Or set this in a system property and grab it here.
var thisGroup = current.getValue('assignment_group');
if (!GRPSYS_ID.includes(thisGroup)) //Exit if thisGroup is not in our list GRPSYS_ID.
return;
var assignJSON = gs.getProperty("rr.last_assigned_to") || ''; //Get the sys_ids of the users most recently assigned to, per group, by this rule.
var assignObj = (assignJSON) ? JSON.parse(assignJSON) : {};
var lstAssigned = assignObj[thisGroup] || '';
//Make an array of all users in the assignment group, ordered alphabetically by name:
var userList = [];
var userHasGroup = new GlideRecord('sys_user_grmember');
userHasGroup.addQuery('user.active', true);
userHasGroup.addQuery('user.u_roundrobin', true);
userHasGroup.addQuery('group', thisGroup);
userHasGroup.orderBy('user.name');
userHasGroup.query();
while (userHasGroup.next())
userList.push(userHasGroup.getValue('user'));
var nextUserIndex = userList.indexOf(lstAssigned) + 1;
if (nextUserIndex == userList.length)
nextUserIndex = 0;
var nextUser = userList[nextUserIndex];
current.assigned_to = nextUser;
assignObj[thisGroup] = nextUser;
assignJSON = JSON.stringify(assignObj);
gs.setProperty("rr.last_assigned_to", assignJSON); //Update the property with the sys_ids of the users most recently assigned to, per group, by this rule.
})(current, previous);
The single group script *does* work:
(function executeRule(current, previous /*null when async*/) {
var GRPSYS_ID = 'f5c8e951db3e4f0000f438ff9d961932'; //Put the sys_id of the assignment group (or groups comma separated) here. Or set this in a system property and grab it here.
var lstAssigned = gs.getProperty("rr.last_assigned_to"); //Get the sys_id of the user most recently assigned to by this rule.
//Make an array of all users in the group(s), ordered alphabetically by name:
var userList = [];
var userHasGroup = new GlideRecord('sys_user_grmember');
userHasGroup.addQuery('user.active', true);
userHasGroup.addQuery('user.u_roundrobin', true);
userHasGroup.addQuery('group', 'IN', GRPSYS_ID);
userHasGroup.orderBy('user.name');
userHasGroup.query();
while (userHasGroup.next())
userList.push(userHasGroup.getValue('user'));
var nextUserIndex = userList.indexOf(lstAssigned) + 1;
if (nextUserIndex == userList.length)
nextUserIndex = 0;
var nextUser = userList[nextUserIndex];
current.assigned_to = nextUser;
gs.setProperty("rr.last_assigned_to", nextUser); //Update the property with the sys_id of the user most recently assigned to by this rule.
})(current, previous);
I don't understand what's going wrong with the top script that stops it from assigning to. Any ideas?