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

GlideAggregate count return zero

gabriel_sk
Tera Contributor

Hello team,

I would like to know if there is a way for GlideAggregate to return zero when a query does not return any result. (more or less as it works with reports)

ex, If i run a query and i want to see the incident count by priority, I would like to see zero show up instead of nothing if there are no incidents for a specific priority.

Sev=[];

var ga = new GlideAggregate('incident');

ga.addEncodedQuery('state=7');
ga.addAggregate('COUNT');
ga.orderBy('priority');

ga.query();

while (ga.next()) ;

var p = ga.prioirty;

Sev.push("Priority " +p + ":" + ga.getAggregate('COUNT'));

}

gs.print(Sev);


Any help is appreciated.

Thanks!

1 REPLY 1

Archana Reddy2
Tera Guru

Hi,

 

The below one should help you. Give it a try and let me know the result.

var Sev=[];

var prior = new GlideAggregate('dl_u_ priority');
prior.addAggregate("COUNT");
prior.groupBy('priority');
prior.query();
while(prior.next())
{
var ga = new GlideAggregate('incident');
ga.addQuery('priority',prior.priority);
ga.query();
Sev.push(ga.getRowCount());
}
gs.print(Sev);

//Tested in Background script
//wrote query for dl_u_priority since the priority of Incident table gets calculated from there

Hope this helps!

Thanks,

Archana