Skip to content

Incident escalation and notifications #1540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
11 changes: 11 additions & 0 deletions Business Rules/Auto Incident Notification and Escalation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Complex Incident Escalation and Notification

## Description
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.

## Features
- Escalate incidents based on priority and time elapsed since creation.
- Notify the assigned group and incident manager.
- Automatically reassign incidents to a higher support group if the SLA is breached.
- Log all actions taken by the Business Rule.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Business Rule: Complex Incident Escalation
// Escalates incidents based on priority and elapsed time since creation.
// Notifies the assigned group and incident manager, reassigns the incident if SLA is breached, and logs all actions.

(function executeRule(current, previous /* null when async */) {
const ESCALATION_THRESHOLD_HOURS = 4;
const SLA_BREACH_THRESHOLD_HOURS = 8;
const HIGHER_SUPPORT_GROUP_ID = gs.getProperty('esc.incident.higher_support_group', '');

if (!HIGHER_SUPPORT_GROUP_ID) {
gs.error('Higher Support Group sys_id not defined. Please configure esc.incident.higher_support_group.');
return;
}
const timeElapsedInHours = parseInt(gs.dateDiff(current.getValue('sys_created_on'), gs.nowDateTime(), true)) / 3600;
if (isEscalationNeeded(current, timeElapsedInHours)) {
escalateIncidentPriority(current);
notifyAssignedGroupAndManager(current);
if (isSLABreached(timeElapsedInHours)) {
reassignToHigherSupportGroup(current, HIGHER_SUPPORT_GROUP_ID);
}

logEscalationActions(current);
}
function isEscalationNeeded(incident, timeElapsed) {
return incident.getValue('state') != 6 && timeElapsed > ESCALATION_THRESHOLD_HOURS;
}
function escalateIncidentPriority(incident) {
const newPriority = Math.max(1, incident.getValue('priority') - 1);
incident.setValue('priority', newPriority);
gs.addInfoMessage('Incident priority has been escalated to ' + newPriority + '.');
}
function notifyAssignedGroupAndManager(incident) {
const assignedGroup = incident.getValue('assignment_group');
const incidentManager = incident.getValue('u_incident_manager');
gs.eventQueue('incident.escalation.notification', incident, assignedGroup, incidentManager);
}
function isSLABreached(timeElapsed) {
return timeElapsed > SLA_BREACH_THRESHOLD_HOURS;
}
function reassignToHigherSupportGroup(incident, groupId) {
incident.setValue('assignment_group', groupId);
gs.addInfoMessage('Incident reassigned to a higher support group due to SLA breach.');
}
function logEscalationActions(incident) {
const logMessage = 'Incident escalated. Priority: ' + incident.getValue('priority') +
', Assigned Group: ' + incident.getValue('assignment_group') +
', Incident Manager: ' + incident.getValue('u_incident_manager');
gs.log(logMessage, 'ComplexIncidentEscalation');
}

})(current, previous);
Loading