Skip to content

Commit ea95bcc

Browse files
authored
Incident escalation and notifications (#1540)
1 parent fb45c6f commit ea95bcc

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Complex Incident Escalation and Notification
2+
3+
## Description
4+
This project demonstrates how to implement a complex Business Rule for incident escalation and notification in ServiceNow. The Business Rule escalates incidents based on priority and time elapsed since creation, notifies the assigned group and incident manager, reassigns the incident to a higher support group if the SLA is breached, and logs all actions taken for auditing purposes.
5+
6+
## Features
7+
- Escalate incidents based on priority and time elapsed since creation.
8+
- Notify the assigned group and incident manager.
9+
- Automatically reassign incidents to a higher support group if the SLA is breached.
10+
- Log all actions taken by the Business Rule.
11+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Business Rule: Complex Incident Escalation
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.
4+
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', '');
9+
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);
20+
}
21+
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');
48+
gs.log(logMessage, 'ComplexIncidentEscalation');
49+
}
50+
51+
})(current, previous);

0 commit comments

Comments
 (0)