diff --git a/Server-Side Components/Background Scripts/Problem from Incident/Creation of Problem b/Server-Side Components/Background Scripts/Problem from Incident/Creation of Problem new file mode 100644 index 0000000000..dbb7541416 --- /dev/null +++ b/Server-Side Components/Background Scripts/Problem from Incident/Creation of Problem @@ -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' +}; diff --git a/Server-Side Components/Background Scripts/Problem from Incident/Readme.md b/Server-Side Components/Background Scripts/Problem from Incident/Readme.md new file mode 100644 index 0000000000..0713eebf80 --- /dev/null +++ b/Server-Side Components/Background Scripts/Problem from Incident/Readme.md @@ -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');