From a0769dac9870b8bca0a2323cf370a9678dbdba5b Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:33:48 +0100 Subject: [PATCH 1/3] Initial create script.js --- .../script.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js diff --git a/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js b/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js new file mode 100644 index 0000000000..82195ed507 --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js @@ -0,0 +1,45 @@ +/* +*Going to define the Incident Closed and Canceled state since we dont want those records as part of our query. +*Also going to leverage the IncidentStateSNC script from ServiceNow +*/ + +/* +*Going to define the Incident Closed and Canceled state since we dont want those records as part of our query. +*/ +var incident_close = IncidentStateSNC.CLOSED; +var incident_canceled = IncidentStateSNC.CANCELED; +var incident_state_query = incident_close + "," + incident_canceled; + +/* +*Creating the Incident State value object that will house the correct incident state since we are working from the Task table. +*Leveraging the IncidentStateSNC script from ServiceNow to get the values that they should be +*/ +var incident_states = { + '1':'New', + '2':'In Progress', + '3':'On Hold', + '6':'Resolved', + '7':'Closed', + '8':'Canceled' +}; + +//Going to create the GlideAggregate object +var ga = new GlideAggregate('task'); +ga.addQuery('state', 'NOT IN', incident_state_query); //Going to exclude the canceled and closed incidents +ga.addQuery('sys_class_name', 'incident'); //Since working on the Task table need to grab only Incident records with task type +ga.groupBy('state'); +ga.groubBy('count'); +ga.addAggregate('COUNT'); +ga.query() + +gs.info('The following is a list of Open Incident records'); + +while (ga.next()) { + + var priorityValue = ga.getDisplayValue('priority'); + var state = ga.getValue('state'); + var count = ga.getValue('COUNT'); + + gs.info("There are a total of: " + count + " Incidents with a priority of " + priorityValue + " and in a state of " + incident_staates[state]); + +} From 5cd1fb0d5a43288ef91277e1ed5cdf2269e2683b Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:43:21 +0100 Subject: [PATCH 2/3] Create README.md --- .../README.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/README.md diff --git a/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/README.md b/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/README.md new file mode 100644 index 0000000000..608e9f25cc --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/README.md @@ -0,0 +1,29 @@ +# Count open Incidents per Priority and State using GlideAggregate + +## Overview +This script will dynamically calculate the **number of open incidents** for each priority level and also give you a total for what +current state the Incident is in using **server-side scripting** +Priority levels typically include: ++ 1 – Critical ++ 2 – High ++ 3 – Moderate ++ 4 – Low + +Incident State typically include: ++ New ++ In Progress ++ On Hold ++ Resolved ++ Closed ++ Canceled + +The scripting solution leverages **GlideAggregate** to efficiently count records grouped by priority and state. This scripts approach +is useful for: ++ Dashboards ++ Business Rules ++ SLA monitoring and reporting + +-- +## Table and Fields ++ **Table:** Task ++ **Fields:** Priority, State From c8d6895ba8d1ae329f3c12d4a76a8fdbd6462eea Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Wed, 29 Oct 2025 11:18:01 -0700 Subject: [PATCH 3/3] Updated mistyped variable --- .../script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js b/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js index 82195ed507..662b5d33e1 100644 --- a/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js +++ b/Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate/script.js @@ -40,6 +40,6 @@ while (ga.next()) { var state = ga.getValue('state'); var count = ga.getValue('COUNT'); - gs.info("There are a total of: " + count + " Incidents with a priority of " + priorityValue + " and in a state of " + incident_staates[state]); + gs.info("There are a total of: " + count + " Incidents with a priority of " + priorityValue + " and in a state of " + incident_states[state]); }