Script
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 07:55 AM
Hi @BharatiK
Use report and that is low code, dont go for script.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 07:58 AM
or
var gr = new GlideRecord('incident'); // Create a GlideRecord object for the 'incident' table
var currentDate = new GlideDateTime(); // Get the current date and time
currentDate.addHours(-24); // Subtract 24 hours from the current date to get the cutoff point
gr.addQuery('closed_at', '<', currentDate); // Query for incidents where 'closed_at' is before 24 hours ago
gr.addQuery('state', '=', '7'); // Optional: Make sure to filter by 'Closed' state (state=7 is Closed in ServiceNow)
gr.query(); // Execute the query
// Loop through the results and log the incident numbers or handle as needed
while (gr.next()) {
gs.info('Incident Number: ' + gr.number + ', Closed At: ' + gr.closed_at);
}
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 08:07 AM
Hello @BharatiK
Check this thread
Solved: Re: How to get incident records which are closed i... - ServiceNow Community
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 08:39 AM
Hello @BharatiK , If you wish to process the Incidents closed before 24 hours, then you can probably make use of Flow designer, below SS can help you write you the same.
But, if you are looking for a script specifically then below can be used: