Script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 07:54 AM
Hi,
How can we get the incident list which are closed before 24hrs using script?
Thanks.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 07:21 AM
Hello @BharatiK
You can use a GlideRecord query to fetch incidents that were closed before 24 hours ago using the closed_at field.
Try this script:
var incGr = new GlideRecord('incident');
var twentyFourHoursAgo = new GlideDateTime();
twentyFourHoursAgo.addDaysUTC(-1); // Subtracts 1 day (24 hours)
incGr.addQuery('state', '7'); // 7 = Closed (Ensure this matches your instance's closed state)
incGr.addQuery('closed_at', '<', twentyFourHoursAgo);
incGr.query();
while (incGr.next()) {
gs.info('Incident: ' + incGr.number + ' | Closed At: ' + incGr.closed_at);
}
This will provide the list of all the incidents which are closed 24hrs before.
Result:
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar