How to get the no of incidents created yesterday with out using encoded query

sivanagalakshmi
Tera Contributor

Hi 

 

Can one help to get no of incidents created yesterday with out using encoded query

 

below is the code I am trying, its not woking whereas it is working with encoded query

 

var gdt= new GlideDate();
gdt.addDays(-1);
gs.print(gdt);
var gr =new GlideAggregate('incident');
gr.addQuery('opened_at', gdt);
gr.addAggregate('COUNT');
gr.query();
if(gr.next()){
gs.info("no on incidents created yesterday:"+ gr.getAggregate('COUNT'));

}
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

The opened_at field is a date/time, and you are comparing it to date only field, so there aren't any records that are equal.  An approach more like this will work

 

var gr =new GlideAggregate('incident');
gr.addQuery('opened_at', '>=', gs.daysAgoStart(1));
gr.addQuery('opened_at', '<=', gs.daysAgoEnd(1));
gr.addAggregate('COUNT');
gr.query();
if(gr.next()){
    gs.print("no of incidents created yesterday:"+ gr.getAggregate('COUNT'));
}

 

 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

The opened_at field is a date/time, and you are comparing it to date only field, so there aren't any records that are equal.  An approach more like this will work

 

var gr =new GlideAggregate('incident');
gr.addQuery('opened_at', '>=', gs.daysAgoStart(1));
gr.addQuery('opened_at', '<=', gs.daysAgoEnd(1));
gr.addAggregate('COUNT');
gr.query();
if(gr.next()){
    gs.print("no of incidents created yesterday:"+ gr.getAggregate('COUNT'));
}