Round Robin Assignment Rule

amitroy
Tera Contributor

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.

27 REPLIES 27

Hi,

Did you have it working OK previously? I can see you added the line we mentioned before: userHasGroup.addQuery('user.u_roundrobin', true);

So just to check, does that field u_roundrobin exist on the sys_user table, and is it ticked true for at least one member of each of the assignment groups?

Looking back at it, it seems the last successful multi-group trial I did was prior to Round Robin yes/no on users, but after shifting to your code for the rr.last_assigned business property. It looked like this:

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 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('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);

u_roundrobin is active on the sys_user table and true for members of both groups, correct...

Should I try security debug or something that might let me see, specifically, where the script "fails?"

Hi again, sorry for my delay getting back to you.

I think the issue may be in the switch from treating all assignment groups together, to treating them individually. Try setting the value of the property 'rr.last_assigned_to' to blank.

I think the code would currently be erroring at line 8 because previously the property would have contained just a sys_id, whereas now line 8 is expecting a JSON string (or blank to start with).

If that doesn't work, check the logs for where the error is occuring. The script debugger is also handy for troubleshooting.

 

No need to apologize, you're doing me a favor! Clearing the system property value was the fix. Thank you so much again!

That's good news :). Could you also mark my answer as correct, to show that the question is answered. thanks.