Insert 10 incidents from Incident table in an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 10:51 AM
Hi All,
How to Insert 10 incidents from Incident table in an array.
Thanks in advance,
Vinuth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 10:58 AM
Hi @vinuth v ,
Please try the below in background script:
var incArr =[];
var incGr = new GlideRecord('incident');
incGr.addActiveQuery();
incGr.setLimit(10);
while(incGr.next())
{
incArr.push(incGr.number.toString());
}
gs.info(incArr);
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 11:18 AM
var gr=new GlideRecord('incident');
gr.intialize();
gr.caller_id='62826bf03710200044e0bfc8bcbe5dd6';
gr.short_description="62826bf03710200044e0bfc8bcbe5dd6+'\n'+test";
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 11:45 AM
Try the below:
var incidentNumbers = [];
for (var i = 0; i < 10; i++) {
var incident = new GlideRecord('incident');
incident.initialize();
incident.short_description = 'Incident Test';
incident.caller_id = '62826bf03710200044e0bfc8bcbe5dd6':
incident.insert();
incidentNumbers.push(incident.number);
}
gs.info('Incidents Created: ' + incidentNumbers.join(', '));
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 11:45 AM - edited 09-07-2024 11:51 AM
This script will create 10 incident records, then result in an array of the new incident Numbers:
var incArr =[];
var cnt = 0;
while (cnt < 10) { //create 10 incident records
var incGr = new GlideRecord('incident');
incGr.initialize();
incGr.caller_id='62826bf03710200044e0bfc8bcbe5dd6';
incGr.short_description='test';
incGr.insert();
incArr.push(incGr.number);
cnt++;
}
gs.info(incArr.join(',');