how to initialize new incident record in glide record

AjayC
Tera Contributor

how to initialize new incident record in glide record

3 REPLIES 3

Bhavya11
Kilo Patron

Hi @AjayC ,

 

  • This is sample code create new record using GlideRecord

 

var incGr = new GlideRecord('incident');

incGr.initialize();

incGr.short_description = 'Test';

incGr.description = 'Hello';

incGr.insert();

 

 

Please mark helpful

 

Thanks,

Bk

 

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

For such basic questions, use ChatGPT or something.

 

For example:


Question:

"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:

  1. Create a new GlideRecord object for the incident table.
  2. Initialize a new record.
  3. Set the desired field values.
  4. 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 the incident table.
  • grIncident.initialize();: This initializes a new, empty record in the incident table.
  • grIncident.field_name = value;: This sets the values for the fields in the new record. Replace field_name with the actual field names and value with the values you want to assign.
  • grIncident.insert();: This inserts the new record into the database and returns the sys_id of the newly created record.

You can customize the script by setting additional fields or modifying the existing ones as per your requirements.

 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Soni Tushar
Tera Guru

Hello @AjayC ,

 

// Create a new GlideRecord object for the 'incident' table
var inc = new GlideRecord('incident');

// Initialize the new record
inc.initialize();

// Set field values
inc.short_description = 'Sample incident'; 
inc.caller_id = 'e4c1f4b87f1423007e16f1d3788f5b99'; 
inc.category = 'Hardware'; 

// Insert the new record into the database
var newIncidentSysId = inc.insert();

// Log the sys_id of the new record
gs.info('New incident created with sys_id: ' + newIncidentSysId);

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!