Skip to content

Commit df5859a

Browse files
authored
Update incident_notification.js
1 parent 1f02a84 commit df5859a

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed
Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
// Business Rule: Complex Incident Escalation
2-
// Escalate incidents based on priority and time elapsed since creation.
3-
// Notify the assigned group and incident manager.
4-
(function executeRule(current, previous /*null when async*/) {
5-
// Constants
6-
var ESCALATION_THRESHOLD_HOURS = 4;
7-
var SLA_BREACH_THRESHOLD_HOURS = 8;
8-
var HIGHER_SUPPORT_GROUP = 'High Priority Support';
2+
// Escalates incidents based on priority and elapsed time since creation.
3+
// Notifies the assigned group and incident manager, reassigns the incident if SLA is breached, and logs all actions.
94

10-
// Calculate time elapsed since incident creation
11-
var timeElapsed = gs.dateDiff(current.getValue('sys_created_on'), gs.nowDateTime(), true);
5+
(function executeRule(current, previous /* null when async */) {
6+
const ESCALATION_THRESHOLD_HOURS = 4;
7+
const SLA_BREACH_THRESHOLD_HOURS = 8;
8+
const HIGHER_SUPPORT_GROUP_ID = gs.getProperty('esc.incident.higher_support_group', '');
129

13-
// Check if the incident is unresolved and time elapsed exceeds the escalation threshold
14-
if (current.getValue('state') != 6 && timeElapsed > ESCALATION_THRESHOLD_HOURS * 3600) {
15-
// Escalate the incident by updating its priority
16-
current.setValue('priority', Math.max(1, current.getValue('priority') - 1));
17-
gs.addInfoMessage('Incident priority has been escalated.');
18-
19-
// Notify the assigned group and incident manager
20-
var assignedGroup = current.getValue('assignment_group');
21-
var incidentManager = current.getValue('u_incident_manager');
22-
gs.eventQueue('incident.escalation.notification', current, assignedGroup, incidentManager);
23-
24-
// Check if the SLA is breached
25-
if (timeElapsed > SLA_BREACH_THRESHOLD_HOURS * 3600) {
26-
// Reassign the incident to a higher support group
27-
current.setValue('assignment_group', HIGHER_SUPPORT_GROUP);
28-
gs.addInfoMessage('Incident has been reassigned to a higher support group due to SLA breach.');
10+
if (!HIGHER_SUPPORT_GROUP_ID) {
11+
gs.error('Higher Support Group sys_id not defined. Please configure esc.incident.higher_support_group.');
12+
return;
13+
}
14+
const timeElapsedInHours = parseInt(gs.dateDiff(current.getValue('sys_created_on'), gs.nowDateTime(), true)) / 3600;
15+
if (isEscalationNeeded(current, timeElapsedInHours)) {
16+
escalateIncidentPriority(current);
17+
notifyAssignedGroupAndManager(current);
18+
if (isSLABreached(timeElapsedInHours)) {
19+
reassignToHigherSupportGroup(current, HIGHER_SUPPORT_GROUP_ID);
2920
}
3021

31-
// Log all actions taken
32-
var logMessage = 'Incident escalated. Priority: ' + current.getValue('priority') + ', Assigned Group: ' + assignedGroup + ', Incident Manager: ' + incidentManager;
22+
logEscalationActions(current);
23+
}
24+
function isEscalationNeeded(incident, timeElapsed) {
25+
return incident.getValue('state') != 6 && timeElapsed > ESCALATION_THRESHOLD_HOURS;
26+
}
27+
function escalateIncidentPriority(incident) {
28+
const newPriority = Math.max(1, incident.getValue('priority') - 1);
29+
incident.setValue('priority', newPriority);
30+
gs.addInfoMessage('Incident priority has been escalated to ' + newPriority + '.');
31+
}
32+
function notifyAssignedGroupAndManager(incident) {
33+
const assignedGroup = incident.getValue('assignment_group');
34+
const incidentManager = incident.getValue('u_incident_manager');
35+
gs.eventQueue('incident.escalation.notification', incident, assignedGroup, incidentManager);
36+
}
37+
function isSLABreached(timeElapsed) {
38+
return timeElapsed > SLA_BREACH_THRESHOLD_HOURS;
39+
}
40+
function reassignToHigherSupportGroup(incident, groupId) {
41+
incident.setValue('assignment_group', groupId);
42+
gs.addInfoMessage('Incident reassigned to a higher support group due to SLA breach.');
43+
}
44+
function logEscalationActions(incident) {
45+
const logMessage = 'Incident escalated. Priority: ' + incident.getValue('priority') +
46+
', Assigned Group: ' + incident.getValue('assignment_group') +
47+
', Incident Manager: ' + incident.getValue('u_incident_manager');
3348
gs.log(logMessage, 'ComplexIncidentEscalation');
3449
}
50+
3551
})(current, previous);

0 commit comments

Comments
 (0)