Using Background script How to get the top 5 close incident records in this year?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 10:10 PM
Dear all,
Scenario-1:-How to get the top 5 close incident records in this year?
var gr = new GlideRecord('incident');
gr.orderBy('number');
gr.setLimit(5);
gr.query();
while(gr.next())
{
gs.print(gr.number);
}
I had written this script. output was showing but not showing close incident.
Can anyone write correct script?
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 10:15 PM
You didn't include a state = closed in your query, so now it's just all. But what do you mean with 'top 5 close incididents'? You are now only looking at 5 random ones.
If my answer helped you in any way, please then mark it as helpful. If it resolved the issue, please mark it as correct.
Mark
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 10:15 PM
Hi
try this
var gr = new GlideRecord('incident');
gr.orderByDesc('closed_at');
gr.setValue('active', 'false');
gr.setLimit(5);
gr.query();
while(gr.next())
{
gs.print(gr.getValue('number'));
}
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2023 08:46 PM
HI for this how would we write script for ,what are the incidents state will be Resolved by next week ?
HOw would we get it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 10:15 PM
Try below
var gr = new GlideRecord('incident');
gr.addQuery('state',3);
gr.orderBy('number');
gr.setLimit(5);
gr.query();
while(gr.next())
{
gs.print(gr.number);
}