From 6f7f61066848fb60b24622c1d4675310760bf2c7 Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:00:22 +0530 Subject: [PATCH 1/3] Create IncidentToChange.js Clone Incident Data into a New Change Request --- .../IncidentToChange.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Copy table fields from one table to another/IncidentToChange.js diff --git a/Server-Side Components/Background Scripts/Copy table fields from one table to another/IncidentToChange.js b/Server-Side Components/Background Scripts/Copy table fields from one table to another/IncidentToChange.js new file mode 100644 index 0000000000..affb9ada41 --- /dev/null +++ b/Server-Side Components/Background Scripts/Copy table fields from one table to another/IncidentToChange.js @@ -0,0 +1,25 @@ +var incidentGR = new GlideRecord('incident'); + +// Replace with actual incident number or sys_id +if (incidentGR.get('number', 'INC0010001')) { // any incident + var changeGR = new GlideRecord('change_request'); + changeGR.initialize(); + + // Copy relevant fields from incident to change request + changeGR.short_description = 'Change for Incident: ' + incidentGR.short_description; + changeGR.description = incidentGR.description; + changeGR.priority = incidentGR.priority; + changeGR.impact = incidentGR.impact; + changeGR.urgency = incidentGR.urgency; + changeGR.category = incidentGR.category; + changeGR.caller_id = incidentGR.caller_id; + changeGR.cmdb_ci = incidentGR.cmdb_ci; // If CI is linked + changeGR.assignment_group = incidentGR.assignment_group; + changeGR.assigned_to = incidentGR.assigned_to; + + // Insert the new change request + var newChangeID = changeGR.insert(); + gs.info('New Change Request created with sys_id: ' + newChangeID); +} else { + gs.info('Incident not found'); +} From 5f4bd9cb6eaf0bcca0fa379c1cf1ae0eec849feb Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Mon, 6 Oct 2025 15:07:03 +0530 Subject: [PATCH 2/3] Create CreationOfIncident.js Creation of Incident --- .../Incident creation/CreationOfIncident.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Incident creation/CreationOfIncident.js diff --git a/Server-Side Components/Background Scripts/Incident creation/CreationOfIncident.js b/Server-Side Components/Background Scripts/Incident creation/CreationOfIncident.js new file mode 100644 index 0000000000..e1378de0ef --- /dev/null +++ b/Server-Side Components/Background Scripts/Incident creation/CreationOfIncident.js @@ -0,0 +1,8 @@ + var incident = new GlideRecord('incident'); + incident.initialize(); + incident.short_description = 'Sample Incident Created via Script'; + incident.description = 'This incident was created using a GlideRecord script.'; + incident.caller_id = gs.getUserID(); // Sets the current user as the caller + incident.priority = 3; // Medium priority + incident.category = 'inquiry'; // Example category + incident.insert(); From f17c6775630a3efd533fe25515358e8fd38431dd Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Mon, 6 Oct 2025 15:08:19 +0530 Subject: [PATCH 3/3] Create Readme.md This script demonstrates how to create an incident record in ServiceNow using the GlideRecord API. It is intended for use in server-side scripting environments such as Script Includes, Business Rules, or background scripts. --- .../Incident creation/Readme.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Incident creation/Readme.md diff --git a/Server-Side Components/Background Scripts/Incident creation/Readme.md b/Server-Side Components/Background Scripts/Incident creation/Readme.md new file mode 100644 index 0000000000..92a44844ca --- /dev/null +++ b/Server-Side Components/Background Scripts/Incident creation/Readme.md @@ -0,0 +1,22 @@ +# ServiceNow Incident Creation Script + +## 📌 Overview +This script demonstrates how to create an incident record in ServiceNow using the GlideRecord API. It is intended for use in server-side scripting environments such as Script Includes, Business Rules, or background scripts. + +## ✅ Prerequisites +- Access to a ServiceNow instance with appropriate permissions. +- Familiarity with JavaScript and ServiceNow scripting. +- The `incident` table must be accessible and modifiable. +- Script should be executed in a server-side context. + +## 🛠️ Script Usage + + +var incident = new GlideRecord('incident'); +incident.initialize(); +incident.short_description = 'Sample Incident Created via Script'; +incident.description = 'This incident was created using a GlideRecord script.'; +incident.caller_id = gs.getUserID(); // Sets the current user as the caller +incident.priority = 3; // Medium priority +incident.category = 'inquiry'; // Example category +incident.insert();