Re-opening existing incidents
The below process lets you re-open a ServiceNow Incident that is in the Resolved state, but not yet Closed. The script has some comments and the full documentation on the Incident Creation Script page can be used to fully tweak this example.
Re-Open Creation Script
(function createServiceNowIncident(scomAlertRecord) {
// ---------------------------------------------
// Re-opening existing incidents example script
// ---------------------------------------------
// Create a GlideRecord object which we'll use to search or create an incident
var grInc = new GlideRecord("incident");
// ------------------------------------------------------------------
// Configure the incident values, combinding some SCOM properties
// ------------------------------------------------------------------
// We will append the object name to the short description for user convinence
var shortDesc = scomAlertRecord.name + " - " + scomAlertRecord.monitoringobjectpath;
// ------------------------------------------------------------------
// Search the incidents table for a resolved incident matching our alert
// ------------------------------------------------------------------
// Short description must match and state must be 6 (Resolved)
grInc.addQuery("short_description", shortDesc);
grInc.addQuery("state", 6);
// Execute the query and proceed to check for results
grInc.query();
// ------------------------------------------------------------------
// Create or update an incident based on the search results
// ------------------------------------------------------------------
if (grInc.next()) {
// Existing incident found, change the status to In Progress
grInc.state = 2;
grInc.work_notes = "Incident re-opened from SCOM Alert";
grInc.update("Incident re-opened from SCOM Alert");
// store the incident to our SCOM record (Don't use scomAlertGr.Update()!)
scomAlertRecord.incident = grInc.sys_id;
} else {
//No matching incidents, create a new one for this alert
grInc.initialize();
// Set the assignment group sys_id for our new incident
grInc.assignment_group = null;
// Populate the description and short description from the SCOM alert
grInc.short_description = shortDesc;
grInc.Description = scomAlertRecord.description;
// Specify our Configuration item by sys_id
grInc.cmdb_ci = null;
// Set the caller of the incident as desired, using the user's sys_id
grInc.caller_id = null;
// insert the new incident and store the created incident to our SCOM record (Don't use scomAlertGr.Update()!)
scomAlertRecord.incident = grInc.insert();
}
})(scomAlertRecord);