Skip to content

Commit 116dad1

Browse files
authored
Smart Assign task to available member (#2190)
* Create README.md * Create implement smart assignment to available group members
1 parent 7a4e347 commit 116dad1

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
**Use-case:**
2+
The primary goal of this UI Action is load-balancing.
3+
It assigns tasks based on the fewest currently Active tasks assigned to a member in a group.
4+
5+
**Example Scenario**:
6+
An assignment group has 10 members. Instead of assigning a new task to the whole group or any random member, the user/agent clicks on
7+
"Smart Assign" to find the member with the fewest currently Active tasks in the same group and assign the task to them.
8+
9+
**UI Action Name:**
10+
Smart Assign
11+
12+
**Condition**: !current.assignment_group.nil() && current.assigned_to.nil()
13+
14+
**How it works:**
15+
1. The code queries the Group members table to find every single user associated with the currently selected assignment group.
16+
If someone removes a previous assignement group and then clicks on Smart Assign button, they are shown an error message to choose an Assignment group.
17+
2. There is a loop on the task table. This loop uses GlideAggregate to count how many active records are assigned to a specific user.
18+
3. It tracks the user that has the lowest count of tasks assigned to them and assigns the current task to them.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var assignedToId = '';
2+
var minOpenTasks = 77777;
3+
var targetGroup = current.assignment_group;
4+
5+
if (!targetGroup) {
6+
gs.addErrorMessage('Please select an Assignment Group first.');
7+
action.setRedirectURL(current);
8+
}
9+
10+
//Finding all active members in the target group
11+
var member = new GlideRecord('sys_user_grmember');
12+
member.addQuery('group', targetGroup);
13+
member.query();
14+
15+
while (member.next()) {
16+
var userId = member.user.toString();
17+
18+
//CountIng the number of active tasks currently assigned to the member
19+
var taskCountGR = new GlideAggregate('task');
20+
taskCountGR.addQuery('assigned_to', userId);
21+
taskCountGR.addQuery('active', true);
22+
taskCountGR.addAggregate('COUNT');
23+
taskCountGR.query();
24+
25+
var openTasks = 0;
26+
if (taskCountGR.next()) {
27+
openTasks = taskCountGR.getAggregate('COUNT');
28+
}
29+
30+
//Checking if this member has fewer tasks than the current minimum
31+
if (openTasks < minOpenTasks) {
32+
minOpenTasks = openTasks;
33+
assignedToId = userId;
34+
}
35+
}
36+
37+
//Assigning the current record to the chosen user
38+
if (assignedToId) {
39+
current.assigned_to = assignedToId;
40+
current.work_notes = 'Assigned via Smart Assign to the user with the fewest active tasks (' + minOpenTasks + ' open tasks).';
41+
current.update();
42+
gs.addInfoMessage('Incident assigned to ' + current.assigned_to.getDisplayValue() + '.');
43+
} else {
44+
gs.addErrorMessage('Could not find an active member in the group to assign the task.');
45+
}
46+
47+
action.setRedirectURL(current);

0 commit comments

Comments
 (0)