Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var CreateProblemFromIncident = Class.create();
CreateProblemFromIncident.prototype = {
initialize: function() {
},

createProblem: function(incidentSysId) {
var incidentGR = new GlideRecord('incident');
if (!incidentGR.get(incidentSysId)) {
gs.error('Incident not found: ' + incidentSysId);
return null;
}

var problemGR = new GlideRecord('problem');
problemGR.initialize();
problemGR.short_description = 'Problem related to: ' + incidentGR.short_description;
problemGR.description = 'Derived from Incident ' + incidentGR.number + ': ' + incidentGR.description;
problemGR.impact = incidentGR.impact;
problemGR.urgency = incidentGR.urgency;
problemGR.priority = incidentGR.priority;
problemGR.cmdb_ci = incidentGR.cmdb_ci;
problemGR.opened_by = gs.getUserID();
problemGR.insert();

// Link the incident to the problem
incidentGR.problem_id = problemGR.sys_id;
incidentGR.update();

return problemGR.sys_id;
},

type: 'CreateProblemFromIncident'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# CreateProblemFromIncident Script Include

This ServiceNow Script Include automates the creation of a Problem record from an existing Incident record.

## 🔧 Functionality

- Fetches the Incident using its `sys_id`.
- Creates a new Problem record with relevant fields copied from the Incident.
- Links the Incident to the newly created Problem via the `problem_id` field.

## 📥 Input

- `incidentSysId`: The `sys_id` of the Incident record.

## 📤 Output

- Returns the `sys_id` of the newly created Problem record.

## 🧪 Example Usage (via Script or Flow)


var creator = new CreateProblemFromIncident();
var newProblemSysId = creator.createProblem('INCIDENT_SYS_ID_HERE');
Loading