From 395dfd8c43da4d86325bf6d8a81cf3d8de7f9693 Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:37:41 +0530 Subject: [PATCH 1/3] script.js --- .../script.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/script.js 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); + } +})(); From 452b02e80ed1dcba0272f243ca6b0195b24fda9e Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:39:16 +0530 Subject: [PATCH 2/3] readme.md --- .../Count All Open Incidents Per Priority/readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/readme.md 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..58ec588a09 --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority/readme.md @@ -0,0 +1,4 @@ +We want to dynamically calculate the number of open incidents for each priority level (1 - Critical, 2 - High, 3 - Moderate, 4 - Low) using server-side scripting. +Table: incident +Field: priority, state +This script uses **GlideAggregate** to count the number of **open incidents** per priority dynamically. Useful for dashboards, automated scripts, or business rules. From e24be9e4bdd9d069bbe91de9501580e3dc87f855 Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:56:49 +0530 Subject: [PATCH 3/3] Update readme.md --- .../readme.md | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) 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 index 58ec588a09..e02e3968dd 100644 --- 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 @@ -1,4 +1,21 @@ -We want to dynamically calculate the number of open incidents for each priority level (1 - Critical, 2 - High, 3 - Moderate, 4 - Low) using server-side scripting. -Table: incident -Field: priority, state -This script uses **GlideAggregate** to count the number of **open incidents** per priority dynamically. Useful for dashboards, automated scripts, or business rules. +# 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`