Regarding groupby priority
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 09:02 PM
how to write script logic in group by priority.
I have tried below one but its not working. please check this once and let me know correct logic.
var gr= new GlideAggregate('incident');
gr.addAggregate('GROUPBY', 'priority');
gr.orderByAggregate('priority');
gr.query();
while (gr.next()) {
var priority = gr.getAggregate('priority');
if (priority === '1 - Critical') {
} else if (priority === '2 - High') {
} else if (priority === '3 - Moderate') {
} else if (priority === '4 - Low') {
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 09:37 PM
Hi @SNOW24,
Try this modified scripts -
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'priority');
agg.orderBy('priority');
agg.groupBy('priority');
agg.query();
while (agg.next()) {
//do things on the results
var incidentCount = agg.getAggregate('COUNT', 'priority');
var priority = agg.getDisplayValue('priority');
var state = agg.getDisplayValue('state');
var assigned_to = agg.getDisplayValue('assigned_to');
if (priority === '1 - Critical') {
gs.info("P1");
gs.info('Display the count {0} and priority {1} assigned to {2} and state {3}', [incidentCount, priority, assigned_to, state]);
} else if (priority === '2 - High') {
gs.info("P2");
gs.info('Display the count {0} and priority {1} assigned to {2} and state {3}', [incidentCount, priority, assigned_to, state]);
} else if (priority === '3 - Moderate') {
gs.info("P3");
gs.info('Display the count {0} and priority {1} assigned to {2} and state {3}', [incidentCount, priority, assigned_to, state]);
} else if (priority === '4 - Low') {
gs.info("P4");
gs.info('Display the count {0} and priority {1} assigned to {2} and state {3}', [incidentCount, priority, assigned_to, state]);
}
}
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 10:07 PM
Hi,
By this simple way you will get the incident count per priority.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 12:12 AM
Hi @SNOW24 ,
If this is resolved then accept the solution so in future other people will refer same.
Thanks.