How to get category with maximum and minimum incidents using glideaggregate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 04:35 AM
Hi All,
I need help to get the category name and count which has maximum and minimum incidents. We can get the count of incidents under all the categories but here i want only max and min count and category.
Thanks,
Vidyashree
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 05:13 AM
Hi @Vidya Shree Make group by Category field in Incident List View. You will get count of incidents by Category.
Regards,
Sid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 05:35 AM
Hi @Sid_Takali
Thank you for your reply.
I looking for script using GlideAggregate which returns only Maximum and Minimum record count category.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 06:03 AM
Hi @Vidya Shree ,
Please refer below script
var incidentGA = new GlideAggregate('incident');
incidentGA.addAggregate('COUNT', 'category');
incidentGA.addAggregate('MAX', 'category');
incidentGA.addAggregate('MIN', 'category');
incidentGA.query();
while (incidentGA.next()) {
gs.print('CATEGORY: ' + incidentGA.getValue('category'));
gs.print('AVG: ' + incidentGA.getAggregate('AVG', 'category'));
gs.print('COUNT: ' + incidentGA.getAggregate('COUNT', 'category'));
gs.print('MAX: ' + incidentGA.getAggregate('MAX', 'category'));
gs.print('MIN: ' + incidentGA.getAggregate('MIN', 'category'));
gs.print(' ');
}
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 06:07 AM
You can also check script as well
var count = new GlideAggregate('incident');
count.addAggregate('MIN', 'sys_mod_count');
count.addAggregate('MAX', 'sys_mod_count');
count.groupBy('category');
count.query();
gs.info(count.getRowCount());
while (count.next()) {
var min = count.getAggregate('MIN', 'sys_mod_count');
var max = count.getAggregate('MAX', 'sys_mod_count');
var category = count.category.getDisplayValue();
gs.info(category + " Update counts: MIN = " + min + " MAX = " + max);
}
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak