Round-Robin (Auto Assignment of new incidents and tasks)

magoo
Kilo Expert

HI All,

 

I was asked to create a round-robin type approach (Auto Assignment) for any incidents/tasks that come into our two level1 groups. What we are looking for is that if its sent to team A's group it will auto assign to the next team member in line, and same with Team B.   I have searched the forums and found a post back from 2008 but it had been deleted by ServiceNow in 2010.   Our company is new to ServiceNow (a couple months now), and I am guessing this is more of a script that would need to run, but currently do not have much experience in scripting.   Has anyone had any luck with doing something like this?   Any suggestions would be greatly appreciated!

 

Thanks!

1 ACCEPTED SOLUTION

justin_drysdale
Mega Guru

We have this in our instance.   Here's the breakdown:



On sys_user, create a date/time field to track last ticket assigned. Also create a checkbox that will be used to determine if the user can receive a ticket.   This can be your vacation exclusion logic.



1. Make an array (associative, key-value) to contain your users that will receive tickets and their corresponding last ticket assigned timestamp.


2. Find your assignment group, and query it's users.


3. Push those users and timestamp into the user array from 1.   You can conditionalize here with the checkbox to make sure you are only pushing 'active' users into the array.


4. Sort the array by timestamp, return the user that has the oldest timestamp.


4.5. Update the user's timestamp.


5. assigned_to = returned user.



Please let me know if you have any questions.


View solution in original post

102 REPLIES 102

Brilliant!

Ken83
Mega Guru

We just moved to utilize this in our instance. I got half way through writing the script for it when i got stuck. The script above from magoo was a tremendous help as I was not able to get the sort functionality to work the way that I wanted. Now it appears to be working flawlessly in Eureka.


xiaix
Tera Guru

So, I created the checkbox "u_round_robin_active" (True/False field), and "u_last_ticket_assigned" (date/time field) in the Users (sys_user) table.



I then created a new Business Rule named: "Round Robin Ticket Assign", using the "Incident" table, not the task table.



Screen Shot 06-09-15 at 10.11 AM.JPG



Here's my "When To Run" settings:



Screen Shot 06-09-15 at 10.12 AM.JPG



Here's my "Action" code:



function onBefore(current, previous)


{      


      gs.sleep(3000); // Sleep statement added to prevent ticket flood being assigned to a single technician.      


      current.assigned_to = resolveTech();//"1e8232ca6ff191007906db3bbb3ee4bd"; // sys_id of a tech in "Service Desk" group;


     


      function resolveTech()


      {


              var tech_arr = [];


              var group = new GlideRecord('sys_user_grmember');


              group.addQuery('group', '8a4cd5b36fd3d1000fd9122cbb3ee48f'); // "Service Desk" group sys_id.


              group.query();


             


              var tech = "";


              var lastAssigned = "";


              var isAssignable = false;


             


              while(group.next())


              {


                      isAssignable = group.user.u_round_robin_active;


                      tech = group.user.sys_id; // "1e8232ca6ff191007906db3bbb3ee4bd";


                      lastAssigned = group.user.u_last_ticket_assigned + "";


                     


                      // Only pushing assignable users to array.


                      if (isAssignable == true)


                      {


                              tech_arr.push({ sys_id: tech, last_assigned: lastAssigned });


                      }


              }      


     


              // Sort on last assigned, return user with.


              tech_arr.sort(function(a, b)


                                          {


                                              return (a.last_assigned < b.last_assigned ? -1:(a.last_assigned > b.last_assigned ? 1:0));


                                          });


              updateDateTime(tech_arr[0].sys_id); // Updating ticket last assigned date


              gs.sleep(2000);


              return (tech_arr[0].sys_id); // Assigned_to technician (sys_id).


      }


     


      function updateDateTime(assignedTo_sysID)


      {


              var nowdt = gs.nowDateTime();


              var updateDate = new GlideRecord('sys_user');


              updateDate.addQuery('sys_id', assignedTo_sysID);


              updateDate.query();


             


              while(updateDate.next())


              {


                      updateDate.u_last_ticket_assigned = nowdt;


                      updateDate.update();


              }


      }      


}



We're running on Eureka, and this is working flawlessly.



I'd like to thank everyone for the huge code contributions!   You've saved me days of work.


Thanks for compiling this, David. We have been testing a slightly customized version of this, and it seems to be working very well!


Is the Round Robin for Incidents only or we can use for Request / Change tickets also???



Looking forward your replies...



Thanks,


Vinoth K