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 951528ffffe6acaf5e92ecca9da46c109721b211 Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:28:37 +0530 Subject: [PATCH 2/3] Create Incident_creation.js Creation of incident --- .../Incident/Incident_creation.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Incident/Incident_creation.js diff --git a/Server-Side Components/Background Scripts/Incident/Incident_creation.js b/Server-Side Components/Background Scripts/Incident/Incident_creation.js new file mode 100644 index 0000000000..46c143b6e0 --- /dev/null +++ b/Server-Side Components/Background Scripts/Incident/Incident_creation.js @@ -0,0 +1,15 @@ +// This script can be used in a Script Include or Business Rule +var incidentGR = new GlideRecord('incident'); +incidentGR.initialize(); + +incidentGR.short_description = 'Critical Incident - Immediate Attention Required'; +incidentGR.description = 'This is a Priority 1 incident created via script.'; +incidentGR.priority = 1; // Priority 1 +incidentGR.impact = 1; // High impact +incidentGR.urgency = 1; // High urgency +incidentGR.caller_id = gs.getUserID(); // Sets the current user as the caller +incidentGR.category = 'network'; // Example category + +// Insert the new record into the database +var newIncidentID = incidentGR.insert(); +gs.info('New Incident created with ID: ' + newIncidentID); From b96ff9452ffc5de9e5ac0889565362e5791bdf47 Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:29:19 +0530 Subject: [PATCH 3/3] Create Readme.md The script programmatically creates a new incident record with high urgency and impact, ensuring it is classified as Priority 1. It sets essential fields such as short description, category, and caller information. --- .../Background Scripts/Incident/Readme.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Incident/Readme.md diff --git a/Server-Side Components/Background Scripts/Incident/Readme.md b/Server-Side Components/Background Scripts/Incident/Readme.md new file mode 100644 index 0000000000..ab80537995 --- /dev/null +++ b/Server-Side Components/Background Scripts/Incident/Readme.md @@ -0,0 +1,43 @@ +# Create Priority 1 Incident in ServiceNow + +This script is designed to create a **Priority 1 incident** in ServiceNow using the GlideRecord API. It can be used in a Script Include, Business Rule, or Background Script to automate the creation of critical incidents. + +## 📝 Script Purpose + +The script programmatically creates a new incident record with high urgency and impact, ensuring it is classified as Priority 1. It sets essential fields such as short description, category, and caller information. + +## ✅ Key Features + +- Initializes a new incident record. +- Sets the following fields: + - `short_description`: Brief summary of the incident. + - `description`: Detailed explanation of the issue. + - `priority`: Set to `1` (Critical). + - `impact`: Set to `1` (High). + - `urgency`: Set to `1` (High). + - `caller_id`: Automatically assigned to the current user. + - `category`: Example category set to `'network'`. +- Inserts the incident record into the database. +- Logs the newly created incident's sys_id. + +## 🚀 Usage + +This script can be placed in: +- A **Script Include** to be called programmatically. +- A **Business Rule** to trigger incident creation based on conditions. +- A **Background Script** for manual execution. + +## 📌 Example + + +var incidentGR = new GlideRecord('incident'); +incidentGR.initialize(); +incidentGR.short_description = 'Critical Incident - Immediate Attention Required'; +incidentGR.description = 'This is a Priority 1 incident created via script.'; +incidentGR.priority = 1; +incidentGR.impact = 1; +incidentGR.urgency = 1; +incidentGR.caller_id = gs.getUserID(); +incidentGR.category = 'network'; +var newIncidentID = incidentGR.insert(); +gs.info('New Incident created with ID: ' + newIncidentID);