The CreatorCon Call for Content is officially open! Get started here.

Auto-Case Assignment based on User Availability

alexsheer
Kilo Contributor

I have a customer  request that requires some heavy scripting on an OnBefore Business rule running on the TASK table--it will set the Assigned To User to the next available user [u_available=true] in the group, taking into considerations the criteria listed below. They are looking to have users  in specific assignment groups randomly assigned tickets--but only if all the criteria is met. I've added an 'Auto Assign Case' checkbox to the group form to specifiy which assignment groups are the ones that if selected, must auto assign the tickets to their users.

How to choose who to randomly assign each ticket is based on the following criteria:
- don't assign if user is in the last hour of their shift (ability to set threshold - 30 min, 60 min, etc.) - by assignment group
- only assign when they're "available" (this will look at the availble flag on the user record as well as the "available to group" flag on the group/user table)
- only assign when the user is not already assigned to a P1 with an outage
- if the skill is their primary, they get priority over another user with the skill as a secondary skill
- if the user has another ticket for the same customer, they get priority

Users are also skipped over if they are working a critical incident with an open outage or have 15 or more open tickets assigned to themselves

 

Does anyone have any experience or guidance on this? I have very limiting scripting skills, any information on this would be a huge help.

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Alex, you should look at ben.hollifield's Queue Manager Solution on Share. While it doesn't address all of your requirement, you can learn an approach on how to accomplish:


ServiceNow Share


View solution in original post

6 REPLIES 6

Aditya Telideva
ServiceNow Employee
ServiceNow Employee

You can try below:


Create On-After business rule and apply this code



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



  var groupName = current.assignment_group;



  // Get a list of members for this group


  var members = [];


  var gm = new GlideRecord('sys_user_grmember');


  gm.addQuery('user.active', true);


  gm.addQuery('group', groupName);


  gm.query();


  while (gm.next()) {


          members.push(String(gm.user));


  }



  // Get a list of their open ticket counts


  var counts = [], agg, count;


  for (var i = 0; i < members.length; i++) {


          count = 0;


          agg = new GlideAggregate('incident');


          agg.addActiveQuery();


          agg.addQuery('assignment_group', groupName);


          agg.addQuery('assigned_to', members[i]);


          agg.addAggregate('COUNT');


          agg.query();


          if (agg.next())


                  count = agg.getAggregate('COUNT');


          counts.push(count);


  }



  // find the minimum count and store its index


  // we cannot use .sort().shift() or we won't know where to look in the members array


  var min = counts[0];


  var index = 0;


  for (var j = 1; j < counts.length; j++) {


          if (counts[j] < min) {


                  min = parseInt(counts[j]);


                  index = parseInt(j);


          }


  }



  // get the member with the lowest count


  var userID = members[index];


  var h;


  // Log their name to verify


  var user = new GlideRecord('sys_user');


  if (user.get(userID)) {


    gs.log('Name: ' + user.sys_id);


  h = user.sys_id;  


  }  


current.assigned_to = h;


current.update();


})(current, previous);


Also, i woud strongly recommend you to please go through the below link:



ServiceNow Share


Thanks,


Aditya Telidevara