Insert 10 incidents from Incident table in an array
Options
- 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
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 11:06 AM
var arr=[];
var gr=new GlideRecord("incident");
gr.addActiveQuery();
gr.setLimit(10);
gr.query();
while(gr.next()){
arr.push(gr.getDisplayValue("number"));
}
gs.print(arr);
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2024 11:24 AM
Hi @vinuth v ,
If you want an array of incident which contains specific field values of the record such as Number, Short Description, Caller then you can you the below script:
var incGR = new GlideRecord("incident");
incGR.addEncodedQuery("<ADD YOUR ENCODED QUERY>"); // Add your query as per requirement
incGR.setLimit(10);
incGR.query();
var incidentArr = []; // Incident Array
while(incGR.next()){
// Preparing the Array of Object based on Incident field values
incidentArr.push({
number: incGR.getValue("number"),
short_description: incGR.getValue("short_description"),
caller: incGR.getDisplayValue("caller_id")
});
}
gs.log(JSON.stringify(incidentArr));
If this solution helps you then, mark it as accepted solution ✔️ and give thumbs up 👍!