Round Robin Assignment of Incidents on Shift Basis

Shankar25
Tera Contributor

Hey All,

 

I Have implemented normal round robin by using some custom fields on sys_user and groups tables with BR's and it works perfectly.

 

But I came up with new requirement where I need to implement Round-Robin of incidents on Shift Basis.

I tries On-call Scheduling functionality but its not working.

 

Some one please suggest me how I can achieve this one.

 

Requirement:

We have an assignment group lets say

 

Assignment Group : XYZ

Members : Apple, Bat, Cobra, Doll, Elephant

Shift 1 : 6 am to 3 pm for Apple

Shift 2: 7 am to 4 pm for Bat and Cobra

Shift 3 : 8 am to 5 pm for Doll

Shift 4 : 9 am to 6 pm for Elephant.

Now when incident is created and assigned at 6 am to group XYZ, incident has to auto assign to "Apple" till 6.59 am.

From 7 am as Bat and cobra comes to shift, When incident is crated and assigned to XYZ group they has to be assigned to Bat followed by cobra and next is again Apple as shift overlap is there/Apple is still in shift.... this repeats for upcoming shifts that is if shift time is satisfied then Incidents has to be assigned in Round-0Robin basis.

 

Please help.

 

Thanks And Regards

Shankar

1 ACCEPTED SOLUTION

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
To achieve this you can assign a schedule to the agent. (There is an OOTB field schedule).

 

When the ticket is come to the queue you can check who all are in the schedule using GlideSchedule API and the method "isInSchedule".

GlideSchedule | ServiceNow Developers

 

Apply the round robin logic on the agents who are in schedule.

 

 

 

 

 


Thanks and Regards,

Saurabh Gupta

View solution in original post

4 REPLIES 4

Alp Utku
Mega Sage

You can create assignment rule(s) on Incident table and set criteria as created between x and y time wise

 

In order to create new assignment rule, please check "sysrule_assignment" table

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
To achieve this you can assign a schedule to the agent. (There is an OOTB field schedule).

 

When the ticket is come to the queue you can check who all are in the schedule using GlideSchedule API and the method "isInSchedule".

GlideSchedule | ServiceNow Developers

 

Apply the round robin logic on the agents who are in schedule.

 

 

 

 

 


Thanks and Regards,

Saurabh Gupta

Hi Saurabh,

 

Thanks for the help.

I have almost achieved the solution, round robin is working as per shift but Incidents are assigning in a random way where some times 2 incidents will be assigned to same person and after that follows round robin.

 

Here is the code that I have implemented.

Please have a look and suggest where it went wrong.

 

(function executeRule(current, previous /*null when async*/ ) {

var groupSysID = current.assignment_group.u_round_robin_group;
var usrArr = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', groupSysID);
grMember.orderBy('user.u_last_assigned_incident_date');
grMember.query();

while (grMember.next()) {
usrArr.push(grMember.user.toString());
}

var currentTicketNumber = gs.getProperty('com.mycompany.current_ticket_number', 0); // Property to store the current ticket number
var totalUsers = usrArr.length;
var scheduleIndex = currentTicketNumber % totalUsers;

var currentUserID = usrArr[scheduleIndex];
var userGr = new GlideRecord('sys_user');
userGr.orderBy('u_last_assigned_incident_date');
if (userGr.get(currentUserID)) {
var scheduleGr = new GlideSchedule(userGr.u_shift_time);
var currentTime = new GlideDateTime();

if (scheduleGr.isInSchedule(currentTime)) {
// Assign ticket to the current user
gs.log('$$$$$Assigning ticket to 1 ' + userGr.name);
current.assigned_to = userGr.sys_id;
currentTicketNumber++;

gs.setProperty('com.mycompany.current_ticket_number', currentTicketNumber);

} else {
// Find the next available user based on the schedule timings
var nextScheduleIndex = (scheduleIndex + 1) % totalUsers;
for (var i = 0; i < totalUsers; i++) {
var nextUserID = usrArr[nextScheduleIndex];
if (userGr.get(nextUserID)) {
var nextScheduleGr = new GlideSchedule(userGr.u_shift_time);
if (nextScheduleGr.isInSchedule(currentTime)) {
// Assign ticket to the next available user
gs.log('$$$$$Assigning ticket to 2 ' + userGr.name);
current.assigned_to = userGr.sys_id;
currentTicketNumber++;

gs.setProperty('com.mycompany.current_ticket_number', currentTicketNumber);

break;
}
}
nextScheduleIndex = (nextScheduleIndex + 1) % totalUsers;
gs.log("$$$$$nextScheduleIndex: " + nextScheduleIndex);
}
}
}
})(current, previous);

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,

Please do not use setProperty method. It will cause a lot of performance issues.

 

 


Thanks and Regards,

Saurabh Gupta