- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 05:17 AM
How to get the *number of incidents opened and not updated during the last 5 days
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 05:45 AM
Hello @rampage
Plz refer the below link for solving your query :-
https://www.servicenow.com/community/developer-forum/not-updated-in-last-5-days/m-p/2174583
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 05:58 AM
@rampage Here is the script for you.
var inc = new GlideAggregate('incident');
inc.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@5^opened_atRELATIVELT@dayofweek@ago@5');
inc.addAggregate('COUNT');
inc.query();
while(inc.next()){
gs.info('Number of incident opend and updated 5 days ago '+inc.getAggregate('COUNT'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 07:08 AM
Hi @rampage ,
You can try below script
// Get the current date and time
var now = new GlideDateTime();
// Calculate the date 5 days ago
var fiveDaysAgo = new GlideDateTime();
fiveDaysAgo.subtractDaysUTC(5);
// Create a new GlideRecord object for the Incident table
var incidentGR = new GlideRecord('incident');
// Add a query to find incidents opened but not updated in the last 5 days
incidentGR.addQuery('sys_updated_on', '<', fiveDaysAgo);
incidentGR.addQuery('active', true); // Optional: Include only active incidents
// Execute the query
incidentGR.query();
// Get the count of incidents that match the query
var numberOfIncidents = incidentGR.getRowCount();
// Log or use the numberOfIncidents variable as needed
gs.info('Number of incidents opened but not updated in the last 5 days: '
+ numberOfIncidents);
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 05:45 AM
Hello @rampage
Plz refer the below link for solving your query :-
https://www.servicenow.com/community/developer-forum/not-updated-in-last-5-days/m-p/2174583
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 05:58 AM
@rampage Here is the script for you.
var inc = new GlideAggregate('incident');
inc.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@5^opened_atRELATIVELT@dayofweek@ago@5');
inc.addAggregate('COUNT');
inc.query();
while(inc.next()){
gs.info('Number of incident opend and updated 5 days ago '+inc.getAggregate('COUNT'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 07:08 AM
Hi @rampage ,
You can try below script
// Get the current date and time
var now = new GlideDateTime();
// Calculate the date 5 days ago
var fiveDaysAgo = new GlideDateTime();
fiveDaysAgo.subtractDaysUTC(5);
// Create a new GlideRecord object for the Incident table
var incidentGR = new GlideRecord('incident');
// Add a query to find incidents opened but not updated in the last 5 days
incidentGR.addQuery('sys_updated_on', '<', fiveDaysAgo);
incidentGR.addQuery('active', true); // Optional: Include only active incidents
// Execute the query
incidentGR.query();
// Get the count of incidents that match the query
var numberOfIncidents = incidentGR.getRowCount();
// Log or use the numberOfIncidents variable as needed
gs.info('Number of incidents opened but not updated in the last 5 days: '
+ numberOfIncidents);
Thanks,
Danish