Reporting - setting thresholds

EthanVanDoorne
Giga Contributor

I have a report that I'd like to run on the number of incidents of a certain template showing the count by user. I currently have this set up as a bar chart, and then it shows a list below with all of the data. I have about 15 users with 2+ incidents which are the only ones I really care about. Is it possible to set a threshold on the count? I can't seem to figure it out.

Bar Chart
Group by: Caller
Aggregation: Count

1 REPLY 1

Jim Coyne
Kilo Patron

Unfortunately, you have to do a bit of coding. First, create a new Script Include with the following properties:



Name: u_reportCallersWithMultipleOpenIncidents
Active: Checked
Client callable: Checked
Script:
function u_reportCallersWithMultipleOpenIncidents(threshold) {
threshold = typeof threshold !== "undefined" ? threshold : 2;
var callerList = "";
var agg = new GlideAggregate("incident");
agg.addAggregate("COUNT","caller_id");
agg.addEncodedQuery("active=true");
agg.groupBy("caller_id");
agg.addHaving("COUNT", ">", threshold);
agg.query();
while (agg.next()) {
callerList += agg.getValue("caller_id") + ",";
}
return callerList;
}


Next, add a filter on your report where "Caller.Sys_id" "is one of" "javascript:u_reportCallersWithMultipleOpenIncidents(2);" (see attached screenshot).
This will call the Script Include function, returning the sys_ids of the Callers. The function is coded so that you can specify different thresholds (e.g. for different reports) and will default to 2 if none is supplied. You can change the

agg.addEncodedQuery("active=true");
line to be whatever you need.

You can check it out in demo014 at the moment. Log in as "admin" and there is a report called "Test".