diff --git a/Core ServiceNow APIs/GlideAggregate/SLA Breach Count by Assignment Group/README.md b/Core ServiceNow APIs/GlideAggregate/SLA Breach Count by Assignment Group/README.md new file mode 100644 index 0000000000..08b13c2d0c --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/SLA Breach Count by Assignment Group/README.md @@ -0,0 +1,8 @@ +**SLA Breached Incident Count by Assignment Group:** +This script uses the GlideAggregate API to calculate the total number of incidents with breached SLAs, grouped by their assignment group. + +**Description:** +This snippet demonstrates how to use GlideAggregate to efficiently group and count ServiceNow records. It retrieves the number of incidents for which SLAs have been breached, grouped by each assignment group. + +**Use Case:** +This is useful for identifying which support groups have the highest number of SLA breaches, helping improve response and resolution performance. diff --git a/Core ServiceNow APIs/GlideAggregate/SLA Breach Count by Assignment Group/getBreachedIncidentCountByGroup.js b/Core ServiceNow APIs/GlideAggregate/SLA Breach Count by Assignment Group/getBreachedIncidentCountByGroup.js new file mode 100644 index 0000000000..5f552b6072 --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/SLA Breach Count by Assignment Group/getBreachedIncidentCountByGroup.js @@ -0,0 +1,24 @@ +function getBreachedIncidentCountByGroup() { + var result = []; + + var ga = new GlideAggregate('task_sla'); + ga.addAggregate('COUNT'); + ga.groupBy('task.assignment_group'); + ga.addQuery('task.sys_class_name', 'incident'); + ga.addQuery('task.active', true); + ga.addQuery('has_breached', true); + ga.query(); + + while(ga.next()){ + var grpName = ga.getValue('task.assignment_group.name') || 'No Group'; + var count = ga.getAggregate('COUNT'); + + result.push({ + assignment_group: grpName, + breached_incident_count: parseInt(count, 10) + }); + + gs.info('Assignment Group: ' + grpName + ' - Breached Incidents: ' + count); + } + return result; +}