Glide record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:39 PM
How to print 5 active incident tickets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:43 PM - edited 12-20-2023 10:51 PM
Hello @soniya patil
Please refer the background script below:
// Create a new GlideRecord for the Incident table
var incidentGR = new GlideRecord('incident');
// Add a condition to filter active incidents
incidentGR.addQuery('active', true);
//This will sort the data by descending order for created field so that you can get the latest 5 INC records
incidentGR.orderByDesc("sys_created_on");
// Limit the result to 5 records
incidentGR.setLimit(5);
// Execute the query
incidentGR.query();
// Loop through the results and print relevant information
while (incidentGR.next()) {
gs.info('Incident Number: ' + incidentGR.number + ', Short Description: ' + incidentGR.short_description);
}
Please modify the query as per your requirement or let me know if you need any help.
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:45 PM
Hi @soniya patil,
Take a look at old thread. It will help you.
How to get first 10 Active records in incident table
how to get the last 10 records in incident table
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:46 PM
Hi @soniya patil The below script will print active 5 incidents by order created on
var inc = new GlideRecord('incident');
inc.addActiveQuery();//only active incidents
inc.orderBy('sys_created_on'); // order by created on
inc.setLimit(5); // set limit 5 since needed only 5 incidents
inc.query();
while(inc.next())
{
gs.info("Incident "+inc.number);
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:46 PM
Hi Soniya,
Below is the script:
var grIncident = new GlideRecord('incident');
grIncident.addQuery('active', true);
grIncident.setLimit(5);
grIncident.query();
while(grIncident.next()){
gs.print(grIncident.getValue('number')); // This will print Incident number when you run it in BG script
}
If my script helps then please mark it Correct.
Thanks,
Utpal