diff --git a/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/readme.md b/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/readme.md new file mode 100644 index 0000000000..e02e3968dd --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/readme.md @@ -0,0 +1,21 @@ +# Count Open Incidents per Priority Using GlideAggregate + +## Overview +This script dynamically calculates the **number of open incidents** for each priority level using **server-side scripting** in ServiceNow. +Priority levels typically include: ++ 1 – Critical ++ 2 – High ++ 3 – Moderate ++ 4 – Low + +The solution leverages **GlideAggregate** to efficiently count records grouped by priority. This approach is useful for: ++ Dashboards ++ Automated scripts ++ Business rules ++ SLA monitoring and reporting + +--- + +## Table and Fields ++ **Table:** `incident` ++ **Fields:** `priority`, `state` diff --git a/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/script.js b/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/script.js new file mode 100644 index 0000000000..3823163d7f --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/script.js @@ -0,0 +1,23 @@ +(function() { + // Create GlideAggregate object on 'incident' table + var ga = new GlideAggregate('incident'); + + // Filter only open incidents (state != Closed (7)) + ga.addQuery('state', '!=', 7); + + // Group results by priority + ga.groupBy('priority'); + + // Count number of incidents per priority + ga.addAggregate('COUNT'); + + ga.query(); + + gs.info('Open Incidents by Priority:'); + + while (ga.next()) { + var priority = ga.priority.getDisplayValue(); // e.g., Critical, High + var count = ga.getAggregate('COUNT'); + gs.info(priority + ': ' + count); + } +})();