Skip to content

Commit e4e86a4

Browse files
authored
Create Smart_Incident_Assignment.js
Smart Incident Assignment – Auto-Assign Incident to Idle Members This server-side solution automatically assigns incidents containing keywords like “disaster” or “emergency” to idle members of a designated support group. It ensures workload is evenly distributed, prevents overloading specific team members, and maintains faster incident response. The assignment group is automatically set, and the system checks each member’s current open incidents before assigning, making the process efficient and balanced.
1 parent 4b43ae4 commit e4e86a4

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ===============================================================
2+
// Smart Incident Assignment – Auto-Assign Incident to Idle Members
3+
// Purpose: Automatically assign disaster/emergency incidents to idle group members to ensure workload balance.
4+
// ===============================================================
5+
6+
(function executeRule(current, previous /*null when async*/) {
7+
8+
// --- Step 1: Check if short description contains disaster or emergency ---
9+
var desc = current.short_description.toLowerCase();
10+
if (desc.indexOf("disaster") === -1 && desc.indexOf("emergency") === -1) {
11+
return; // Exit if keywords are not present
12+
}
13+
14+
// --- Step 2: Define the target assignment group ---
15+
var groupName = "Support Group"; //group name as per the requirment
16+
var groupGR = new GlideRecord('sys_user_group');
17+
groupGR.addQuery('name', groupName);
18+
groupGR.query();
19+
if (!groupGR.next()) return; // Exit if group not found
20+
var groupSysId = groupGR.sys_id;
21+
22+
// --- Step 3: Set the assignment group ---
23+
current.assignment_group = groupSysId;
24+
25+
// --- Step 4: Get all active members of the group ---
26+
var memberGR = new GlideRecord('sys_user_grmember');
27+
memberGR.addQuery('group', groupSysId);
28+
memberGR.query();
29+
30+
var availableMembers = [];
31+
while (memberGR.next()) {
32+
var userId = memberGR.user.sys_id;
33+
34+
// --- Step 5: Check if user already has an open incident ---
35+
var incidentGR = new GlideRecord('incident');
36+
incidentGR.addQuery('assigned_to', userId);
37+
incidentGR.addQuery('state', '<', 7); // Excludes Closed/Resolved
38+
incidentGR.query();
39+
40+
if (!incidentGR.hasNext()) {
41+
availableMembers.push(userId); // Collect idle members
42+
}
43+
}
44+
45+
// --- Step 6: Assign incident to first available idle member ---
46+
if (availableMembers.length > 0) {
47+
current.assigned_to = availableMembers[0];
48+
} else {
49+
gs.addInfoMessage('All members of the Support Closed Group currently have active incidents.');
50+
}
51+
52+
})(current, previous);

0 commit comments

Comments
 (0)