HR matching rules / assignment logic don't work correctly if the user moving the case out of draft state doesn't have permission to read cases and therefore is unable to obtain a correct count of agent workload.

Steps to Reproduce


  1. For simplicity, install HR Core and HR SP without demo data.

  2. Add two users to HR Tier 1 and give them all HR skills.

  3. Remove location from the sys_user records for your agents.

  4. Find a set of users who have no HR roles and remove their location (eliminating the country matching part of assignment logic).

  5. Create a case as one of these users, and note who it was assigned to.

  6. Create a second case as a DIFFERENT non-HR user.

    It is important to be different as a user can view their own cases, so if you are the same user, then the count of caseload will be correct.

    If things are working properly, this case would go to the second agent. It may go to the second agent by happenstance, so keep creating cases for DIFFERENT end users with no HR roles until you see that the case load is not being distributed based upon agent workload.



// below is the corrected function in script include sn_hr_core.hr_AssignmentUtil (sys id: 205cba709f221200d9011977677fcf21)
_sortAgentsByLeastLoaded: function(agents) {
var ids = [];
if (gs.nil(agents) || !agents.length)
return [];
try {
var assignCount = {};
var assignedTo;
var caseCount;
// get count of assigned cases per agent
var count = new GlideAggregate('task');
count.addQuery('assigned_to', 'IN', agents);
count.addQuery('active', 'true');
count.addQuery('sys_class_name', 'INSTANCEOF', 'sn_hr_core_case').addOrCondition('sys_class_name', 'INSTANCEOF', 'sn_hr_core_task');
count.addAggregate('COUNT', 'assigned_to');
count.orderByAggregate('COUNT', 'assigned_to');
while ( {
assignedTo = count.assigned_to;
caseCount = parseInt(count.getAggregate('COUNT', 'assigned_to'));
assignCount[assignedTo] = caseCount;
// The query returns only those agents with assignments. Any agents not returned are added to list with a count of zero
var list = [];
for (var i = 0; i  < agents.length; i++) {
var id = agents[i];
var obj = {'id' : id};
var cnt = assignCount[id];
if (!gs.nil(cnt))
obj['value'] = cnt;
obj['value'] = 0;
//sort the list by count
list.sort(function (a, b) {
if (a.value > b.value)
return 1;
if (a.value < b.value)
return -1;
return 0;
for (var index = 0; index  < list.length; index++)
} catch (err) {
gs.error("Error in get agents by least loaded list: "+ err.message);
ids = agents;
return ids;

Related Problem: PRB1290209

Seen In

There is no data to report.

Fixed In

Jakarta Patch 10
Kingston Patch 8

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2019-05-21 11:38:05