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'); +} 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(); 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();