Glide aggregate count

Avinash Dubey2
Tera Contributor

I have written below script to calculate the count of priority.I want to display the count of individiual priority.I am not able to display all three at once.

var gr = new GlideAggregate('incident');
var strQuery ='priority=1';
var strQuery1 ='priority=2';
var strQuery2 ='priority=3';
gr.addEncodedQuery(strQuery);
gr.addAggregate('COUNT');
gr.query();
gr.next();

var t1 = gr.getAggregate('COUNT');
gs.print(t1);
gr.addEncodedQuery(strQuery1);
gr.addAggregate('COUNT');
gr.query();
gr.next();
var t2 = gr.getAggregate('COUNT');
gs.print(t2);

gr.addEncodedQuery(strQuery2);
gr.addAggregate('COUNT');
gr.query();
gr.next();
var t3 = gr.getAggregate('COUNT');
gs.print(t3);

1 ACCEPTED SOLUTION

Swathi P
Tera Guru

Hi Avinash ,

You can try the below script to print all at once .

var gr = new GlideAggregate('incident');
gr.addEncodedQuery('priorityIN1,2,3');
gr.addAggregate('COUNT', 'priority');
gr.query();
while (gr.next()) {
 var incidentCount = gr.getAggregate('COUNT', 'priority');
var priority = gr.getValue('priority');
gs.info('Display the count {0} and priority{1} ', [incidentCount, priority]);
}

View solution in original post

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage
Hello @Avinash Dubey ,
You can follow below script and pass encoded queries 
 
var agg = new GlideAggregate('incident'); 
agg.addAggregate('COUNT', 'priority'); 
agg.addEncodedQuery('priority=1'); 
agg.query(); 
while (agg.next()) 
{ //do things on the results
 var incidentCount = agg.getAggregate('COUNT', 'priority'); 
gs.print('Display the count {0}', [incidentCount]); 
}

MARK MY ANSWER CORRECT IF IT HELPS YOU

Swathi P
Tera Guru

Hi Avinash ,

You can try the below script to print all at once .

var gr = new GlideAggregate('incident');
gr.addEncodedQuery('priorityIN1,2,3');
gr.addAggregate('COUNT', 'priority');
gr.query();
while (gr.next()) {
 var incidentCount = gr.getAggregate('COUNT', 'priority');
var priority = gr.getValue('priority');
gs.info('Display the count {0} and priority{1} ', [incidentCount, priority]);
}