PRINT INCIDENT CATEGORY BASED
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 08:34 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 09:04 AM - edited 11-13-2022 09:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 04:24 PM
Can you help me to print total number of incidents here as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 08:23 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 12:21 AM
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');