The CreatorCon Call for Content is officially open! Get started here.

Number of incidents opened and not updated during the last 5 days

rampage
Tera Contributor

How to get the *number of incidents opened and not updated during the last 5 days

3 ACCEPTED SOLUTIONS

Samaksh Wani
Giga Sage

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

View solution in original post

Sandeep Rajput
Tera Patron
Tera Patron

@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'));
}

View solution in original post

Danish Bhairag2
Tera Sage

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

 

View solution in original post

3 REPLIES 3

Samaksh Wani
Giga Sage

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

Sandeep Rajput
Tera Patron
Tera Patron

@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'));
}

Danish Bhairag2
Tera Sage

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