Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This functionality automatically assigns newly created or updated tickets to the most available user within the assigned group, based on their current workload.

When a ticket is assigned to a group, the system evaluates all active members of that group, calculates the number of open or active tasks each member currently owns, and assigns the ticket to the user with the least workload. This ensures fair and efficient distribution of tasks across team members, helping prevent overload on specific users and improving overall response time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function executeRule(current, previous /*null when async*/) {

// Add your code here
if (!current.assignment_group || current.assigned_to)
return;

var userWorkload = {};
var grp = current.assignment_group;
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', grp);
grMember.query();
while (grMember.next()) {
var userId = grMember.user.toString();
var inc = new GlideAggregate('incident');
inc.addAggregate('COUNT');
inc.addQuery('assigned_to', userId);
inc.addQuery('state', 'NOT IN', '6,7'); // not resolved or closed
inc.query();

if (inc.next()) {
userWorkload[userId] = parseInt(inc.getAggregate('COUNT'), 10);
} else {
userWorkload[userId] = 0;
}
}

// Find user with minimum workload
var minUser = null;
var minCount = Number.MAX_VALUE;
for (var u in userWorkload) {
if (userWorkload[u] < minCount) {
minCount = userWorkload[u];
minUser = u;
}
}

if (minUser) {
current.assigned_to = minUser;
gs.info('Auto-assigned incident to user: ' + minUser);
}

})(current, previous);
Loading