Incidents created from past 3 days

Supriya KM
Tera Contributor

Hello Everyone,

I need to get the incidents which are created from past 3 days using script. can anyone help me in achieving this.

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

hi @Supriya KM ,

Please use below script to get the count of incidents which are created on past 3 days.

var ga = new GlideAggregate("incident");
ga.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@03'); //get incidnets created on last 3days
ga.addAggregate("COUNT");
ga.query();
while (ga.next()) {
   gs.info("Total Count is " +ga.getAggregate("COUNT")); //get the count
}

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi @Supriya KM ,

Try Below script using Bachground script or fix script:

var count = '';
var gr = new GlideRecord('incident');
gr.addQuery('caller_id=681ccaf9c0a8016400b98a06818d57c7^sys_created_onRELATIVEGE@dayofweek@ago@3'); // sys_id of joe employeeuser
gr.query();
//gs.print('Count'+gr.getRowCount());
while(gr.next()){
count++;
}
gs.print('Count'+gr.getRowCount());

 

SandeepDutta_0-1665388092079.png

 

 

Community Alums
Not applicable

Hello,

Could you please try below script - 

 

var gd = new GlideRecord('incident');
gd.addEncodedQuery('sys_created_onRELATIVEGE@dayofweek@ago@3');
gd.query();
while(gd.next()) {
//var num = gd.number;
}
gs.print('name : '+gd.getRowCount());

 

 

Pavankumar_1
Mega Patron

hi @Supriya KM ,

Please use below script to get the count of incidents which are created on past 3 days.

var ga = new GlideAggregate("incident");
ga.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@03'); //get incidnets created on last 3days
ga.addAggregate("COUNT");
ga.query();
while (ga.next()) {
   gs.info("Total Count is " +ga.getAggregate("COUNT")); //get the count
}

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Supriya KM
Tera Contributor

Thank you Pavan, it worked!!!