How to get category with maximum and minimum incidents using glideaggregate

Vidya Shree
Kilo Sage

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

6 REPLIES 6

Hi @Community Alums 

 

Thank you for your reply.

The result i am expecting is different. For example if the database category is having maximum number of incidents it should display category name along with the count. Same for category with minimum incidents.

In the below screenshot i want only Inquiry and Database to be displayed

VidyaShree_0-1716475532511.png

 

Thanks

Vidyashree

Community Alums
Not applicable

Hi @Vidya Shree ,

Please try below script this will give you maximum and minimum Incident Category

var count=new GlideAggregate('incident');
count.addAggregate('MAX','category');
count.addAggregate('MIN','category');
count.setGroup(false);
count.query();
while(count.next()){
    gs.print(count.getAggregate('MAX','category'));
	gs.print(count.getAggregate('MIN','category'));
}

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak