
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2018 06:25 AM
Hello SN Comm!
Looking to see if anyone can help me out with this one. I know that the system can auto-assign based off of Skills in the HR area. I am wondering if there is also some setup that can be implemented, for HR Cases to auto-assign throughout an assignment group in rotation/workload.
We have our main HR Employee Resource Center assignment group (HR call center), they get a ton of emails in daily that generates General Inquiry cases assigned to their group first. Then their supervisor will go through all those unassigned cases that come in via email, look through them, and assign based on who she feels should take that case. Whether it be someone within her own team, or assign to another assignment group.
This process, due to so many incoming emails, takes her about 3 hours a day to comb through in order to assign out. She could better spend her time on other more important things, such as actually working on some of the cases herself, or other HR Operational daily tasks.
Again, I know all about the auto-assignment based on skills, but that is not what we are looking for here. I want to know if the system has something to assign to a group based on rotation/workload (round-robin style if you will).
Thanks in advance!
-Rob
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 05:19 AM
Hey Shalini,
Thanks for responding. You are very close to what I will want to use actually. I knew about matching skills, but do not want to use that for my scenario. I did however, find a similar document from what you sent me.
With this, I will need to explore 'Selection Criteria' as the Resource when creating a matching rule. Then, I will be able to use the Criteria of 'Last Assigned', and go from there.
Thanks again for helping me out!
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 09:00 PM
Hi Rob, you can configure your assignment rules to auto-assign email cases to the support agents based on the HR skill. There is a nice section on matching rules in HR documentation. You may find that useful.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 05:19 AM
Hey Shalini,
Thanks for responding. You are very close to what I will want to use actually. I knew about matching skills, but do not want to use that for my scenario. I did however, find a similar document from what you sent me.
With this, I will need to explore 'Selection Criteria' as the Resource when creating a matching rule. Then, I will be able to use the Criteria of 'Last Assigned', and go from there.
Thanks again for helping me out!
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2024 01:15 PM
Hi!
I realize there may be built out solutions out there by now, but this is definitely something I've thought about but never got around to! Using the modulo operator ('%') in a business rule would be a particularly elegant approach.
Here's a toy example followed by some code you could draw from to fit your needs:
- Assign John, Mary, and Alice an 'Agent Number' starting from 0 (store in a field somewhere)
- John is 0
- Mary is 1
- Alice is 2
- Bob is 3
- Create a business rule that will run after an HR case is inserted.
- In this business rule have a script that will use the HR case number (e.g. HRC0001325) to calculate which agent (via agent number) the case gets assigned to
- the first part of the script in the business rule should remove the starting 'HRC' and any leading zeros from the HR case string (e.g. HRC0001325 becomes 1325); let's call this the 'Extracted/Cleaned' case number
- then, the script will use the 'modulo' operator on the Extracted/Cleaned case number with the total number of agents we want to rotate between (in our case, there are four, John, Mary, Alice, Bob).
- Modulo on the Extracted/Cleaned case number tells you who should be assigned the case. Try it out -- it works on any number of agents. Here's an example with our four agents using the case numbers HRC0001325, HRC0001326, HRC0001327, HRC0001328
- Agent 1 (Agent Mary) is assigned to: HRC0001325
- 1325 % 4 = 1 (Translation: the remainder when dividing 1325 by 4 is 1.)
- Agent 2 (Agent Alice) is assigned to: HRC0001326
- 1326 % 4 = 2 (Translation: the remainder when dividing 1326 by 4 is 2.)
- Agent 3 (Agent Bob) is assigned to: HRC0001327
- same as above...
- Agent 4 (Agent John) is assigned to: HRC0001328
- And... that's pretty much it! The business rule or could change the Assigned To field based off the modulo calculation.
Here's some code to illustrate how this would work -- you would just need to implement in a business rule and store agent numbers or mapping somewhere.
// Helper function to extract digits and remove leading zeros
function extractAndCleanNumber(caseID) {
// Step 1: Extract digits from the case ID
var justNumbers = caseID.replace(/\D/g, ''); // Replace non-digit characters
// Step 2: Remove leading zeros
return justNumbers.replace(/^0+/, ''); // Remove leading zeros
}
// Helper function to determine the agent index using modulo
function moduloAssignment(caseNumber, numAgents) {
if (numAgents === 0) {
gs.error("Number of agents cannot be zero.");
return -1; // Return -1 to indicate an error state
}
return caseNumber % numAgents;
}
// Agent list (John, Mary, Alice, Bob) mapped to numbers 0, 1, 2, 3
var agents = ['John', 'Mary', 'Alice', 'Bob'];
var numAgents = agents.length;
// Example case IDs
var caseIDs = [
'HRC0001325',
'HRC0001326',
'HRC0001327',
'HRC0001328'
];
// Iterate over the case IDs and assign agents
for (var i = 0; i < caseIDs.length; i++) {
var caseID = caseIDs[i];
// Step 1: Extract and clean the case number from the case ID
var caseNumber = parseInt(extractAndCleanNumber(caseID), 10);
// Step 2: Determine the agent index using modulo
var agentIndex = moduloAssignment(caseNumber, numAgents);
// Step 3: Get the assigned agent's name
if (agentIndex >= 0) {
var assignedAgent = agents[agentIndex];
// Log the assignment
gs.info(
"Agent " + assignedAgent + " (Agent Number: " + agentIndex + ") is assigned to: " + caseID
);
} else {
gs.error("Failed to assign an agent for Case ID: " + caseID);
}
}
Some disclaimers and workarounds
Where this is easiest to implement:
* Scenarios where there is one group where you want to round robin cases
* Scenarios where there is reliable / consistent HRC case enumerations (e.g. there are no automations that skip case creation for some reason... or scenarios where a subset of cases go to another group -- this would result in an imbalanced assignment)
* Group is relatively stable; if group size changes frequently this could also result in imbalance
Potential workarounds if you don't have reliable/consistent HRC case enumerations
For example: let's pretend that we want to do round robin assignment for a brand new tier 2 group.
Tier 2 groups come after a tier 1 group first reviews. Most times for these situations, tier 2 will not have as reliable / consistent HRC case enumerations (e.g. queue might look like HRC0001325, HRC0001330, HRC0001337)
* if the modulo approach is desired, we need to find a way to get reliable/consistent case enumeration. For example, you could have a 'modulo_id' field attached to each HR case that shadows any incoming case assignments.
So if we pretend that we have a brand new tier 2 group and HRC0001325 is the very first case... then HRC0001325 is modulo_id 1; HRC0001330 is modulo_id 2; and HRC0001337 is modulo_id 3.
Then we could use the modulo operator on the modulo id instead of the Extracted/Cleaned HRC.
Final Note
The above is just one approach for leveraging the modulo operator. As with most ServiceNow things, there's probably many other ways to do this.
Even as I write this, I realize there's probably a neat way to leverage modulo within HR assignment rules rather than in a business rule!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 09:36 AM
In this case, the agent with the least cases will get the assigned case according to skill.
Mark Helpful if it worked for you. It worked great for New York release.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var temp = [];
var arrUser = [];
var counter = 0;
var r = current.skills.getDisplayValue();
var f = r.split(",");
var c = f.length;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.assignment_group);
gr.query();
while (gr.next()) {
var sk = new GlideRecord('sys_user_has_skill');
sk.addQuery('user', gr.user);
sk.query();
counter = 0;
while (sk.next()) {
if (current.skills.includes(sk.skill)) {
counter++;
}
}
if (c == counter)
arrUser.push(gr.user.toString());
}
var userID;
for (var i = 0; i < arrUser.length; i++) {
var count;
var ga = new GlideAggregate('sn_hr_core_case');
ga.addQuery('active', 'true');
ga.addQuery('assigned_to', arrUser[i]);
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
count = ga.getAggregate('COUNT');
temp.push(count);
var minimum = Math.min.apply(Math, temp);
if (count == minimum) {
userID = arrUser[i];
}
}
}
if (current.assigned_to.nil())
gs.addInfoMessage("Sorry, no agents match your skill criteria");
current.assigned_to = userID;
})(current, previous);