ServiceNow incident resolution

This version of the Gateway for ServiceNow provides functionality for providing ServiceNow incident resolution data.

By default, ServiceNow instances enforce a rule that requires the Resolution Code field (table field name: close_code) and Resolution Notes field (table field name: close_notes) to be populated when the incident is set to Resolved or Closed. These fields correspond to the CloseCode and CloseNotes fields in the ObjectServer respectively.

The Resolution Code field must be set to one of the defined options in the ServiceNow instance. This field is a text string and can be customized by defining additional options. The Resolution Notes field must also be populated when the Resolution Code is provided, but can be set to any value.

The gateway maps events in the ObjectServer that have Severity set to Clear into ServiceNow as incidents with State set to Resolved. The gateway provides a method to specify values for these fields so that the event is inserted/updated into ServiceNow correctly with the Resolution Code and Resolution Notes fields populated appropriately.

Updating the gateway to support ServiceNow Incident Resolution

If you are upgrading from a previous version of the Gateway for ServiceNow, use the following steps to enable the gateway to support ServiceNow Incident Resolution:

  1. Update the alerts.status table to add the new columns: CloseCode and CloseNotes:
    ```
    alter table alerts.status add column CloseCode varchar(64);
    go
    
    alter table alerts.status add column CloseNotes varchar(64);
    go
    ```
  2. Edit the updatePayload() function in the servicenow.generic.js JavaScript file to specify the default values for CloseCode and CloseNotes.
    
    //
    // This function is executed before an event is inserted/updated into 
    // ServiceNow and is intended to allow for the overriding of values in the event.
    // The functionality defined below allows for the close_code and close_notes 
    // fields to be overridden with new values.
    //
    // @param inputs
    //      A Map of values for the event being processed by the gateway.
    //
    function updatePayload(inputs, operation) {
    
    	if (operation === "insert" || operation === "update") {
    		var severity = inputs.get("severity");
    		if (severity === 0) {
    			var new_close_code = "Closed/Resolved by Caller";
    			inputs.put("close_code", new_close_code);
    			var new_close_notes = "Event Severity set to 0 at object server\.";
    			inputs.put("close_notes", new_close_notes);
    
    			logger.debug("generic.js returning close_code=" + new_close_code + " and close_notes=" + new_close_notes 
    				+ " for " + operation + " to the gateway.");
    		}
    	}
    	else if (operation === "delete") {
    		// At this point, the event is already deleted at the object server
    		// So we set the values for the fields required to be replicated to ServiceNow
    		var new_close_code = "Closed/Resolved by Caller";
    		inputs.put("close_code", new_close_code);
    		var new_close_notes = "Event deleted at object server\.";
    		inputs.put("close_notes", new_close_notes);
    		var state_closed = 7;
    		inputs.put("state", state_closed);
    
    		logger.debug("generic.js returning close_code=" + new_close_code + " and close_notes=" + new_close_notes + " and state=" 
    			+ state_closed + " for " + operation + " to the gateway.");
    	}
    	
    	return inputs;
    }```
    
    

    The function above provides Closed/Resolved by Caller for the close_code field and Provided by Netcool/OMNIbus ServiceNow Gateway for events with Severity=0 (Clear).

    You should update the function to specify the correct values for the fields as needed. Be aware that as the script is written in JavaScript, JavaScript syntax applies here.

    Once the changes have been performed, restart the gateway for the changes to take effect.

  3. Ensure the inboundUpdate function in the servicenow.notification.js file includes the CloseCode and CloseNotes fields:
    ```
    //
    // Update an alert with data received from ServiceNow
    //
    // Params:
    //   alert - The alert being updated
    //   inputs - Input values, as a name/value map, for the update
    function inboundUpdate(alert,inputs)
    {
    	try {
    		// Dates can be parsed using dateformat.parse.
    		// The format used is as used by the Java SimpleDateFormat class.
    		// http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
    		//
    		// Example:
    		// var resolvetime = dateformat.parse("dd/MM/yyyy' 'HH:mm:ss", inputs.get("ResolveTime"));
    		values = sog.newrow();
    		values.put("ServiceNowState", inputs.get("state"));
    		values.put("TTNumber", inputs.get("number"));
    		values.put("CloseCode", inputs.get("close_code"));
    		values.put("CloseNotes", inputs.get("close_notes"));
    		alert.update(values);
    		if( null == inputs.get("sys_id") ) {
    			addJournal(alert, "Ticket updated in ServiceNow with TTNumber: " + inputs.get("number") + " and state: " + inputs.get("state"));
    		} else {
    			addJournal(alert, "Ticket updated in ServiceNow with SysId: " + inputs.get("sys_id") + " and TTNumber: " + inputs.get("number") + " and state: " + inputs.get("state"));
    		}
    	} catch(err) {
    		logError(alert, "Unable to update alert in OMNIbus: " + err);
    	}
    }
    ```
    

Removing support for the ServiceNow Incident Resolution

If you are working with a ServiceNow instance that does not enforce the rule requiring Resolution Code for Resolved Incidents, remove support for ServiceNow Incident Resolution using the following steps:

  1. Edit the updatePayload() function in the servicenow.generic.js JavaScript file to remove the functionality to provide the CloseCode and CloseNotes data:
    ```
    function updatePayload(inputs, operation) {
    	return inputs;
    }
    ```
  2. Remove the CloseCode and CloseNotes fields from the inboundUpdate function in servicenow.notification.js:
    ```
    //
    // Update an alert with data received from ServiceNow
    //
    // Params:
    //   alert - The alert being updated
    //   inputs - Input values, as a name/value map, for the update
    function inboundUpdate(alert,inputs)
    {
    	try {
    		// Dates can be parsed using dateformat.parse.
    		// The format used is as used by the Java SimpleDateFormat class.
    		// http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
    		//
    		// Example:
    		// var resolvetime = dateformat.parse("dd/MM/yyyy' 'HH:mm:ss", inputs.get("ResolveTime"));
    		values = sog.newrow();
    		values.put("ServiceNowState", inputs.get("state"));
    		values.put("TTNumber", inputs.get("number"));
    		alert.update(values);
    		if( null == inputs.get("sys_id") ) {
    			addJournal(alert, "Ticket updated in ServiceNow with TTNumber: " + inputs.get("number") + " and state: " + inputs.get("state"));
    		} else {
    			addJournal(alert, "Ticket updated in ServiceNow with SysId: " + inputs.get("sys_id") + " and TTNumber: " + inputs.get("number") + " and state: " + inputs.get("state"));
    		}
    	} catch(err) {
    		logError(alert, "Unable to update alert in OMNIbus: " + err);
    	}
    }
    ```
    
  3. Optional: remove the CloseCode and CloseNotes fields from the ObjectServer:
    ```
    alter table alerts.status drop column CloseCode;
    go
    
    alter table alerts.status drop column CloseNotes;
    go
    ```

    After making the changes, restart the gateway for the changes to take effect.