Skip to content

xmatters/xm-labs-ServiceNow-Major-Incident-Enhancement

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

ServiceNow Major Incident Enhancement

This ServiceNow xMatters Integration enhancement will add ServiceNow Major Incident Management into the xMatters notification process. Accepting a major incident will trigger xMatters notification.

Pre-Requisites

Files

  • If you have not made any customizations to your ServiceNow xMatters integration you can import the above xml file to ServiceNow.

How it works

xMatters notifications will not be created unless a Major Incident has been "Accepted" in ServiceNow.

Other Major incident statuses, "Proposed" and "Rejected" will not trigger an xMatters notification.

This Major Incident ServiceNow Enhancement will allow one of your teams to review an incident and decide whether it is considered major. At this time if the incident is "Approved", an xMatters notification will be created.

Important Note: This enhancement will stop all notifications from going to xMatters except for "Approved" Major Incidents. If you still want to send xMatters notifications for other incidents, you may need to make further customizations. The way you implement ServiceNow Major Incident Process could change the way this integration works. See Configuring ServiceNow Major Incident Process section for further details.

Installation

Modify xMatters Incident Insert Business Rule script include

  1. Search for "xMattersConfig" and open the Script include.


  1. Ensure you are working in the xMatters application scope. Click on the "here" link to edit the record if you are not.

  2. On "When to run", Add the Following Filter Condition:

    "Major incident state" is "Accepted"

  3. Click Update.

You can import the script changes using XML files if ALL of the following are true:

  • You HAVE ServiceNow xMatters integration v5.0.
  • You have NOT made any modifications to the script include xMattersConfig.
  • You have NOT made any modifications to the script include xMattersIncident.

If any of the above conditions are NOT true, DO NOT Import XML Files, follow instructions here instead.

Import the following XML files

  1. Import the xMattersConfig Script Include XML File

    Follow the ServiceNow instructions here.

  2. Import the xMattersIncident Script Include XML File

    Follow the ServiceNow instructions here.

  3. The installation is complete, now you can Configuring ServiceNow Major Incident Process.

To import you can right click in the header of any list (Users, Groups, Incidents, etc). Instructions above include additional permissions that may be required.



Manually Update ServiceNow Script Includes

Follow This Step if ANY of the following are true:

  • If you have installed any version of xMatters ServiceNow integration other than v5.0.
  • Servicenow xMattersConfig script include HAS been modified.
  • ServiceNow xMattersIncident Script include HAS been modified.

If your version of xMatters ServiceNow integration is not v5.0 you can upgrade to v5.0. Alternatively, you can still use this enhancement but will need to make highlighted changes keeping in mind that your code may differ slightly. You should be able to use this same method with older versions with little or no modifications. The surrounding code may differ slightly.

Modify xMattersConfig script include

  1. Search for "xMattersConfig" and open the Script include.


  1. Ensure you are working in the xMatters application scope. Click on the "here" link to edit the record if you are not.

  2. Locate and update the TRIGGER_RULES: {} object. This should be around line 39.

Original Code:

TRIGGER_RULES: {
  ASSIGNMENT: 'Assignment',
  PRIORITY_UPGRADE: 'Priority Upgrade',
  SLA_ALERT: 'SLA Alert',
  REOPENED: 'Reopened',
  DELETE: 'Delete'
},



Make the following code changes, highlighted with the comments:
//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************
and
//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

Updated Code:

TRIGGER_RULES: {

//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

  MAJOR_INCIDENT_ACCEPTED: 'Major Incident Confirmed',

//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

  ASSIGNMENT: 'Assignment',
  PRIORITY_UPGRADE: 'Priority Upgrade',
  SLA_ALERT: 'SLA Alert',
  REOPENED: 'Reopened',
  DELETE: 'Delete'
},
  1. Save the script.

Modify xMattersIncident script include

  1. Search for "xMattersIncident" and open the Script include.


  1. Ensure you are working in the xMatters application scope. Click on the "here" link to edit the record if you are not.

  2. Make the following modifications:



A. Locate and update the isUpdateValid function . This should be around line 90.

Original Code:

/**
  * Condition for the "Update" Incident Business Rule
  * @param  {GlideRecord[Incident]}  incident  the "current" incident glide record
  * @param  {GlideRecord[Incident]}  incident_prev  the "previous" incident glide record
  * @return {Boolean}          Whether or not the Business Rule should fire
*/
isUpdateValid: function (incident, incident_prev) {
    var shouldRun = false;
    if (!this.config.INCIDENT.ENABLED) {
        reason = 'feature is disabled';
    } else {
        var criteria = this.getUpdateCriteria(incident, incident_prev);
        reason = 'no incident condition was met';
        if (criteria.isValidPriority) {
            if (criteria.isActive) {
      
        if (criteria.isPriorityUpgrade || !criteria.wasActive || criteria.isSLAEscalation || criteria.isAssignment || !criteria.wasAcceptedMajorIncident) {
          
          shouldRun = true;
          reason = '| CONDITION : met active |';
        }					
            } else if (criteria.wasActive) {
                shouldRun = true;
                reason = '| CONDITION : Closure |';
            }
        } else if (criteria.wasValidPriority) {
            shouldRun = true;
            reason = '| CONDITION : Priority Downgrade |';
        } else {
            reason = 'Priority not in configured priority | ' + incident.priority + ' !IN ' +
                this.config.INCIDENT.VALID_PRIORITIES;
        }
    }
    if (!shouldRun) {
        this.log.debug('isUpdateValid: Bypassing Incident Business Rule | Reason: ' + reason);
    }
    return shouldRun;
},



Make the following code changes, highlighted with the comments:
//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************
and
//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

Updated Code:

/**
  * Condition for the "Update" Incident Business Rule
  * @param  {GlideRecord[Incident]}  incident  the "current" incident glide record
  * @param  {GlideRecord[Incident]}  incident_prev  the "previous" incident glide record
  * @return {Boolean}          Whether or not the Business Rule should fire
*/
isUpdateValid: function (incident, incident_prev) {
    var shouldRun = false;
    if (!this.config.INCIDENT.ENABLED) {
        reason = 'feature is disabled';
    } else {
        var criteria = this.getUpdateCriteria(incident, incident_prev);
        reason = 'no incident condition was met';
        if (criteria.isValidPriority) {
            if (criteria.isActive) {



//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

      if (criteria.isAcceptedMajorIncident) {
        if (criteria.isPriorityUpgrade || !criteria.wasActive ||
          criteria.isSLAEscalation || criteria.isAssignment || !criteria.wasAcceptedMajorIncident || criteria.isSnowAssignment) {
          
          shouldRun = true;
          reason = '| CONDITION : met active |';
        }
      }	

//***********************************************************				
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************



            } else if (criteria.wasActive) {
                shouldRun = true;
                reason = '| CONDITION : Closure |';
            }
        } else if (criteria.wasValidPriority) {
            shouldRun = true;
            reason = '| CONDITION : Priority Downgrade |';
        } else {
            reason = 'Priority not in configured priority | ' + incident.priority + ' !IN ' +
                this.config.INCIDENT.VALID_PRIORITIES;
        }
    }
    if (!shouldRun) {
        this.log.debug('isUpdateValid: Bypassing Incident Business Rule | Reason: ' + reason);
    }
    return shouldRun;
},



B. Locate and update the beforeUpdate function . This should be around line 150.

Original Code:

/**
  * Logic for the "Update" Incident Business Rule - Will conditionally create an incident event
  * @param  {GlideRecord[Incident]}  incident  the "current" incident glide record
  * @param  {GlideRecord[Incident]}  incident_prev  the "previous" incident glide record
*/
beforeUpdate: function (incident, incident_prev) {
    var triggerRule = '';
    var eventParameters;
    var criteria = this.getUpdateCriteria(incident, incident_prev);

    if (criteria.isValidPriority) {
        if (criteria.isActive) {
          
      if (criteria.isPriorityUpgrade) { // Priority escalation
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.PRIORITY_UPGRADE;
      } else if (!criteria.wasActive) { // Reopen
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.REOPENED;
      } else if (criteria.isSLAEscalation) { // SLA Alert
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.SLA_ALERT;
      } else if (criteria.isAssignment) { // assignee/group flow
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.ASSIGNMENT;
      } 
                    
      if (triggerRule !== '') {
        eventParameters = {
          triggerRule: triggerRule,
          terminate: true,
          sendEvent: true
        };
      }
    
      } else if (criteria.wasActive) { // Issue resolved
          eventParameters = {
              triggerRule: this.config.INCIDENT.TRIGGER_RULES.DELETE,
              terminate: true,
              sendEvent: false
          };
  
      }
    } else if (criteria.wasValidPriority) { // Priority decreased
        eventParameters = {
            triggerRule: this.config.INCIDENT.TRIGGER_RULES.DELETE,
            terminate: true,
            sendEvent: false
        };

    }
    if (typeof eventParameters !== 'undefined' && eventParameters !== null) {
        eventParameters.userName = gs.getUserName();
        this.log.debug("beforeUpdate: Queuing event from incident update business rule, eventParameters: " + this.json.encode(eventParameters));

        if (!incident) {
            this.log.debug('beforeUpdate: "incident" parameter not set or null; using "current": ' + this.json.encode(current));
            incident = current;
        }
        gs.eventQueue(this.getEventQueue(incident.number), incident, this.json.encode(eventParameters), 'incidentUpdate');
    }
},



Make the following code changes, highlighted with the comments:
//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************
and
//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

Updated Code:

/**
  * Logic for the "Update" Incident Business Rule - Will conditionally create an incident event
  * @param  {GlideRecord[Incident]}  incident  the "current" incident glide record
  * @param  {GlideRecord[Incident]}  incident_prev  the "previous" incident glide record
*/
beforeUpdate: function (incident, incident_prev) {
    var triggerRule = '';
    var eventParameters;
    var criteria = this.getUpdateCriteria(incident, incident_prev);

    if (criteria.isValidPriority) {
        if (criteria.isActive) {
    
//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

    if (criteria.isAcceptedMajorIncident) {

//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************


      if (criteria.isPriorityUpgrade) { // Priority escalation
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.PRIORITY_UPGRADE;
      } else if (!criteria.wasActive) { // Reopen
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.REOPENED;
      } else if (criteria.isSLAEscalation) { // SLA Alert
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.SLA_ALERT;
      } else if (criteria.isAssignment) { // assignee/group flow
        triggerRule = this.config.INCIDENT.TRIGGER_RULES.ASSIGNMENT;
      } 


//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

      else if (criteria.wasAcceptedMajorIncident == false && criteria.isAcceptedMajorIncident == true) { // Major Incident confirmed
            triggerRule = this.config.INCIDENT.TRIGGER_RULES.MAJOR_INCIDENT_ACCEPTED;
        }

//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************


      if (triggerRule !== '') {
        eventParameters = {
          triggerRule: triggerRule,
          terminate: true,
          sendEvent: true
        };
      }
      
//*********************************************************** 
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

    }

//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************
    
        } else if (criteria.wasActive) { // Issue resolved
            eventParameters = {
                triggerRule: this.config.INCIDENT.TRIGGER_RULES.DELETE,
                terminate: true,
                sendEvent: false
            };
    
        }
    } else if (criteria.wasValidPriority) { // Priority decreased
        eventParameters = {
            triggerRule: this.config.INCIDENT.TRIGGER_RULES.DELETE,
            terminate: true,
            sendEvent: false
        };

    }
    if (typeof eventParameters !== 'undefined' && eventParameters !== null) {
        eventParameters.userName = gs.getUserName();
        this.log.debug("beforeUpdate: Queuing event from incident update business rule, eventParameters: " + this.json.encode(eventParameters));

        if (!incident) {
            this.log.debug('beforeUpdate: "incident" parameter not set or null; using "current": ' + this.json.encode(current));
            incident = current;
        }
        gs.eventQueue(this.getEventQueue(incident.number), incident, this.json.encode(eventParameters), 'incidentUpdate');
    }
},



C. Locate and update the getUpdateCriteria function . This should be around line 150.

Original Code:

/**
  * Gets a view of the state of the current record based on the different business rule
  * criteria.
  * @param  {GlideRecord[Incident]}  incident  the "current" incident glide record
  * @param  {GlideRecord[Incident]}  incident_prev  the "previous" incident glide record
  * @return {Object}          Returns an object with information about the state of the current incident
  *                                and what type of conditions/criteria are being met
*/
getUpdateCriteria: function (incident, incident_prev) {
    var criteria = {
        isValidPriority: this.isIncidentPriorityValid(incident),
        wasValidPriority: this.isIncidentPriorityValid(incident_prev),
        isActive: this.isIncidentActive(incident),
        wasActive: this.isIncidentActive(incident_prev),
    };
    if (criteria.isValidPriority && criteria.isActive) {
        criteria.isPriorityUpgrade = incident.priority < incident_prev.priority;
        criteria.isSLAEscalation = incident.escalation.changes() && incident.escalation > incident_prev.escalation &&
            incident_prev.escalation != -1;
  criteria.isAssignment = (incident.assigned_to.changes() && !incident.assigned_to.nil()) ||
            (!incident.assignment_group.nil() && (incident.assigned_to.changes() || incident.assignment_group.changes()));
    
    }

    this.log.debug('getUpdateCriteria: Criteria: ' + global.JSON.stringify(criteria));
    return criteria;
},



Make the following code changes, highlighted with the comments:
//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************
and
//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

Updated Code:

/**
  * Gets a view of the state of the current record based on the different business rule
  * criteria.
  * @param  {GlideRecord[Incident]}  incident  the "current" incident glide record
  * @param  {GlideRecord[Incident]}  incident_prev  the "previous" incident glide record
  * @return {Object}          Returns an object with information about the state of the current incident
  *                                and what type of conditions/criteria are being met
*/
getUpdateCriteria: function (incident, incident_prev) {
    var criteria = {


//***********************************************************
//[xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************

  isAcceptedMajorIncident: this.isAcceptedMajorIncident(incident),
  wasAcceptedMajorIncident: this.isAcceptedMajorIncident(incident_prev),

//***********************************************************
//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]
//***********************************************************


        isValidPriority: this.isIncidentPriorityValid(incident),
        wasValidPriority: this.isIncidentPriorityValid(incident_prev),
        isActive: this.isIncidentActive(incident),
        wasActive: this.isIncidentActive(incident_prev),
    };
    if (criteria.isValidPriority && criteria.isActive) {
        criteria.isPriorityUpgrade = incident.priority < incident_prev.priority;
        criteria.isSLAEscalation = incident.escalation.changes() && incident.escalation > incident_prev.escalation &&
            incident_prev.escalation != -1;
  criteria.isAssignment = (incident.assigned_to.changes() && !incident.assigned_to.nil()) ||
            (!incident.assignment_group.nil() && (incident.assigned_to.changes() || incident.assignment_group.changes()));
    
    }

    this.log.debug('getUpdateCriteria: Criteria: ' + global.JSON.stringify(criteria));
    return criteria;
},



D. Directly after the getUpdateCriteria function edited above, add the following code:

//[xmLabs - Major Incident Management Enhancement - xMatters]

isAcceptedMajorIncident : function(incidentRec){
  return (incidentRec.major_incident_state == 'accepted');
},

//End Changes [xmLabs - Major Incident Management Enhancement - xMatters]

E. Save the script.



Configuring ServiceNow Major Incident Process

To make this work, you will either need to:

Once you have Proposes a Major Incident Candidate in ServiceNow you can:

You can also use the following to manage Major Incidents in ServiceNow:

Troubleshooting

If the events are not making it into xMatters, then check out the System Logs in ServiceNow for any error messages. This enhancement uses the same logging setting as the Incident workflow, so update the Logging setting in the main xMatters Configuration page to get more or less detail.