"servicenow how to initialize new incident record in glide record"
Answer:
To initialize a new Incident record using GlideRecord in ServiceNow, you'll follow these steps:
- Create a new GlideRecord object for the
incident
table. - Initialize a new record.
- Set the desired field values.
- Insert the record into the database.
Here is an example of how you can do this in a server-side script (e.g., in a Business Rule, Script Include, etc.):
// Create a new GlideRecord object for the 'incident' table
var grIncident = new GlideRecord('incident');
// Initialize a new record in the 'incident' table
grIncident.initialize();
// Set field values for the new incident record
grIncident.short_description = 'Short description of the incident';
grIncident.caller_id = 'sys_id_of_caller'; // Replace with the actual sys_id of the caller
grIncident.category = 'software';
grIncident.priority = 2; // Priority 2 - High
// Insert the new record into the database
var incidentSysId = grIncident.insert();
// Optionally, you can log the sys_id of the newly created incident
gs.log('New incident created with sys_id: ' + incidentSysId);
Explanation:
var grIncident = new GlideRecord('incident');
: This line creates a new GlideRecord object for theincident
table.grIncident.initialize();
: This initializes a new, empty record in theincident
table.grIncident.field_name = value;
: This sets the values for the fields in the new record. Replacefield_name
with the actual field names andvalue
with the values you want to assign.grIncident.insert();
: This inserts the new record into the database and returns thesys_id
of the newly created record.
You can customize the script by setting additional fields or modifying the existing ones as per your requirements.