GlideAggregate count return zero
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2018 07:49 AM
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!
Labels:
- Labels:
-
Analytics and Reports
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2018 09:52 AM
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