|
| 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