- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 11:47 AM
How to know the count of incidents in each priority i.e., in priority - 1 or 2 or 3 or 4 or 5 separately by using background script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 11:57 AM
Hello @NBK ,
You can use this script to get the count of incidents per priority :
var agg = new GlideAggregate('incident');
agg.addAggregate('count', 'priority');
agg.orderBy('priority');
agg.query();
while (agg.next()) {
var priority = agg.priority.getDisplayValue();
var count = agg.getAggregate('count', 'priority');
var agg2 = new GlideAggregate('incident');
agg2.addAggregate('count', 'priority');
agg2.orderBy('priority');
gs.info(priority + ": number of incidents:" + count);
}
I hope you find this helpful!
Best regards,
Hajar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 12:02 PM
@NBK Here is the script.
var incidentPriority = new GlideAggregate('incident');
incidentPriority.addAggregate('COUNT');
incidentPriority.groupBy('priority');
incidentPriority.query();
while(incidentPriority.next()){
gs.info(incidentPriority.getDisplayValue('priority')+'('+incidentPriority.getAggregate('COUNT')+')');
}
Here is how the output looks
Here is how it looks when group by in the list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 12:08 PM
Hello @NBK ,
// Create a GlideAggregate object for the incident table
var inc = new GlideAggregate('incident');
// Add a group by clause for the priority field
inc.addAggregate('COUNT', 'priority');
// Group by priority
inc.groupBy('priority');
// Query the records
inc.query();
// Iterate through the result
while (inc.next()) {
var priority = inc.getValue('priority');
var count = inc.getAggregate('COUNT', 'priority');
gs.info('Priority ' + priority + ': ' + count + ' incidents');
}
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 11:57 AM
Hello @NBK ,
You can use this script to get the count of incidents per priority :
var agg = new GlideAggregate('incident');
agg.addAggregate('count', 'priority');
agg.orderBy('priority');
agg.query();
while (agg.next()) {
var priority = agg.priority.getDisplayValue();
var count = agg.getAggregate('count', 'priority');
var agg2 = new GlideAggregate('incident');
agg2.addAggregate('count', 'priority');
agg2.orderBy('priority');
gs.info(priority + ": number of incidents:" + count);
}
I hope you find this helpful!
Best regards,
Hajar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 12:02 PM
@NBK Here is the script.
var incidentPriority = new GlideAggregate('incident');
incidentPriority.addAggregate('COUNT');
incidentPriority.groupBy('priority');
incidentPriority.query();
while(incidentPriority.next()){
gs.info(incidentPriority.getDisplayValue('priority')+'('+incidentPriority.getAggregate('COUNT')+')');
}
Here is how the output looks
Here is how it looks when group by in the list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 12:08 PM
Hello @NBK ,
// Create a GlideAggregate object for the incident table
var inc = new GlideAggregate('incident');
// Add a group by clause for the priority field
inc.addAggregate('COUNT', 'priority');
// Group by priority
inc.groupBy('priority');
// Query the records
inc.query();
// Iterate through the result
while (inc.next()) {
var priority = inc.getValue('priority');
var count = inc.getAggregate('COUNT', 'priority');
gs.info('Priority ' + priority + ': ' + count + ' incidents');
}
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!