- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 11:57 PM
Hi Team,
I have a requirement to show the number of incidents based on categories. Can anyone help me with the script to show these records as it is below:
Hardware :12
Software : 3
Database : 23
Inquiry/Help : 40
Regards
Souvick
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 12:00 AM
Hi @Souvick A
Please use below script:
var incidents = new GlideAggregate('incident');
incidents.addAggregate('count', 'category'); // Add an aggregate to count based on category field
incidents.orderBy('category');
incidents.query();
while (incidents.next()) {
// Get the current category and count
var category = incidents.category;
var count = incidents.getAggregate('count', 'category');
gs.info('Category: ' + category + ' Count: ' + count);
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 02:09 AM
Hi @imranmotad,
var incidents = new GlideAggregate('incident');
incidents.addAggregate('count', 'category'); // Add an aggregate to count based on category field
incidents.orderBy('category');
incidents.query();
while (incidents.next()) {
// Get the current category and count
var category = incidents.category.getDisplayValue(); // Get display value of category field
var count = incidents.getAggregate('count', 'category');
gs.info('Category: ' + category + ' Count: ' + count);
// Now, if you want to get incident numbers for each category, you can add another query
var incidentNumbers = [];
var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('category', category); // Query for incidents with the current category
incidentGr.query();
while (incidentGr.next()) {
incidentNumbers.push(incidentGr.number.getDisplayValue()); // Get display value of incident number
}
gs.info('Incident Numbers for Category ' + category + ': ' + incidentNumbers.join(', '));
}
Thanks
SP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 10:28 PM
You can try this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 07:14 AM