
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 03:45 AM - edited 03-09-2023 03:48 AM
Hi Team,
We have requirement about Round Robin assignment using Schedules
We have different schedules for a group of members like below:
Schedule 1: 7am - 4pm
Schedule 2: 8am - 5pm
Schedule 3: 9am - 6pm
Schedule 4: 10am - 7pm
If user is in 7am-4pm schedule, we can directly assign the tickets to him from 7am to 8am, after that second person will join and based on Round Robin, we need to assign the tickets to them.
Same way, if user is in 8am-5pm, based on Round robin only we need to assign the ticket to schedule 1, schedule2, and schedule 3 persons.
FYI, We have idea about checking current time in schedule or not. But, how to start this requirement to satisfy all the conditions.
We have written sample code for above requirement: Please modify if anything required.
var usrArr = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', '217db28047e12110a789fa8bd36d43a6');
grMember.orderBy('user.u_last_assigned_incident_date');
grMember.query();
while(grMember.next()) {
usrArr.push(grMember.user);
}
gs.print(usrArr.length);
for(var i=0;i<=usrArr.length;i++){
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id',grMember.user);
usr.query();
if(usr.next()){
var sched = new GlideSchedule(usr.u_shift_schedule);
var curTime = new GlideDateTime();
gs.print(sched.isInSchedule(curTime));
if(sched.isInSchedule(curTime)){
gs.print("Yes: "+grMember.user.name);
}
else{
gs.print("No: "+grMember.user.name);
}
}
}
Please provide your approaches to solve this requirement.
Thanks & Regards,
Prasanna Kumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:46 AM
First, you need to identify the members who are available to take the ticket based on their schedules.
For each schedule, you need to check if any member is available during the current time. You can use the GlideSchedule API to check if a member is in schedule or not.
Once you have identified the available members for each schedule, you can implement the Round Robin algorithm to assign tickets to them. You can keep track of the last member who was assigned a ticket and assign the next ticket to the next available member in the list.
If there are no available members for a schedule, you can skip that schedule and move on to the next one.
// Get all the members of the group
var usrArr = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', '217db28047e12110a789fa8bd36d43a6');
grMember.orderBy('user.u_last_assigned_incident_date');
grMember.query();
while(grMember.next()) {
usrArr.push(grMember.user);
}
// Get the current time
var curTime = new GlideDateTime();
// Loop through each schedule
for (var i = 1; i <= 4; i++) {
var schedule = "Schedule " + i;
var availableMembers = [];
// Check if any member is available during the current time
for (var j = 0; j < usrArr.length; j++) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', usrArr[j]);
user.query();
if (user.next()) {
var userSchedule = new GlideSchedule(user.u_shift_schedule);
if (userSchedule.isInSchedule(curTime)) {
availableMembers.push(user.sys_id);
}
}
}
// If there are no available members for this schedule, skip it
if (availableMembers.length == 0) {
continue;
}
// Get the last member who was assigned a ticket for this schedule
var lastAssigned = gs.getProperty(schedule + " Last Assigned");
if (lastAssigned == "") {
lastAssigned = availableMembers[0];
}
// Assign the ticket to the next available member in the list
var nextAssigned = "";
for (var k = 0; k < availableMembers.length; k++) {
if (availableMembers[k] == lastAssigned) {
if (k == availableMembers.length - 1) {
nextAssigned = availableMembers[0];
} else {
nextAssigned = availableMembers[k+1];
}
break;
}
}
// Update the last assigned property for this schedule
gs.setProperty(schedule + " Last Assigned", nextAssigned);
gs.print("Ticket assigned to " + nextAssigned + " for " + schedule);
Note: In this code, we are using ServiceNow's global properties to store the last assigned member for each schedule. You need to create a global property for each schedule with the name "Schedule x Last Assigned" (replace "x" with the schedule number) before running the code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:08 AM
@SatyakiBose Thank you for your help. can you please elaborate Advanced Work Assignment, what is the Plugin Name and is it free or require licensing cost. Also, provide any videos regarding that implementation.
Thanks & Regards,
Prasanna Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:12 AM
You can find more details about Advanced Work Assignment here:
You can check the implementation video here - https://www.youtube.com/watch?v=fANNto5TG-0
The plugin is free and no cost attached.