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,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');
}
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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();
Loading