PRINT INCIDENT CATEGORY BASED

ARAVIND22
Tera Contributor

@Ankur Bawiskar / Team, Help!!! Needed

 

 Please need your input on this please help me as I NEED TO PRINT INCIDENT CATEGORY BASED WITHOUT ENCODED QUERY  ,

 

I NEED SOLUTIION IN BOTH WAYS I MEAN GLIDE RECORD AND GLIDE AGGREGATE

NEED TO GET OUTPUT BASED ON SCREENSHOT

 

var agg = new GlideAggregate('incident');
agg.addAggregate('count', 'category');
agg.orderBy('category');
agg.query();
while (agg.next()) {
var category = agg.category;
var count = agg.getAggregate('count', 'category');
var agg2 = new GlideAggregate('incident');
agg2.addAggregate('count', 'category');
agg2.orderBy('category'); 
gs.info(category + ": Current number of incidents:" + count);
}

OUTPUT I AM GETTING ::

 

BUT TOTAL NUMBER INCIDENT SHOULD BE 

 

*** Script: : Current number of incidents: 4 -> WHY 4 HERE IT SHOULD BE 68 PLEASE HELP ME
*** Script: database: Current number of incidents:2
*** Script: hardware: Current number of incidents:10
*** Script: inquiry: Current number of incidents:33
*** Script: network: Current number of incidents:5
*** Script: software: Current number of incidents:13

 

PLEASE VERIFY THE SCREENHOT

4 REPLIES 4

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Where are you printing the the total count? The number 4 you see is actually the number of Incidents which do not have any category.

 

Please use the below script:-

 

var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT');
agg.query();
while (agg.next()) {
var category = agg.category;
var count = agg.getAggregate('COUNT');
gs.info("Total Incidents"+count);
var agg2 = new GlideAggregate('incident');
agg2.addAggregate('count', 'category');
agg2.orderBy('category'); 
agg2.query();
while (agg2.next()) {
var category = agg2.category;
var count = agg2.getAggregate('count', 'category');
gs.info(category + ": Current number of incidents:" + count);
}
}

 

Please mark my answer as correct based on Impact.

Can you help me to print total number of incidents here as well

Hello,

 

The script I shared earlier will print the total number of incidents.

 

Sharing it again please use the below script:-

 

var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT');
agg.query();
while (agg.next()) {
var category = agg.category;
var count = agg.getAggregate('COUNT');
gs.info("Total Incidents"+count);
var agg2 = new GlideAggregate('incident');
agg2.addAggregate('count', 'category');
agg2.orderBy('category'); 
agg2.query();
while (agg2.next()) {
var category = agg2.category;
var count = agg2.getAggregate('count', 'category');
gs.info(category + ": Current number of incidents:" + count);
}
}

 

Please mark my answer as correct based on Impact.

escape
Tera Contributor

The error is the category and count variables are already defined.

Here is the updated code:

var category1 = agg2.category;
var count1 = agg2.getAggregate('count', 'category');