From 19683894be1f4df50cf3ca78e2c41c11c0ff0438 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Sun, 19 Oct 2025 21:08:57 +0530 Subject: [PATCH 1/2] Create 01ReadMe.md --- .../01ReadMe.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Get incident count based on priority/01ReadMe.md diff --git a/Server-Side Components/Background Scripts/Get incident count based on priority/01ReadMe.md b/Server-Side Components/Background Scripts/Get incident count based on priority/01ReadMe.md new file mode 100644 index 0000000000..b3b0e82908 --- /dev/null +++ b/Server-Side Components/Background Scripts/Get incident count based on priority/01ReadMe.md @@ -0,0 +1,45 @@ +Incident Priority Counter — ServiceNow Script: + +This script counts the number of incidents for each priority in your ServiceNow instance and outputs the results in the system logs. It’s useful for analyzing incident distribution, identifying trends, and generating quick reports on priority levels. + +Purpose / Use Case: + +Quickly see how many incidents exist at each priority level (Critical, High, Medium, Low, etc.). + +Useful for monitoring workloads or checking data consistency. + +Can serve as a template for other field-based analytics in ServiceNow. + +How It Works: + +Queries all records in the Incident table. + +Loops through each record and retrieves the priority field (display value). + +Counts how many incidents exist for each priority. + +Outputs the results to system logs (gs.info()). + +Installation / Usage: + +Navigate to System Definition → Scripts – Background. + +Paste the script into the editor. + +Click Run Script. + +Check System Logs → All to see the output in the format: + +Priority: Critical | Count: 10 +Priority: High | Count: 25 +Priority: Medium | Count: 30 +Priority: Low | Count: 5 +Priority: No Priority Set | Count: 2 + +Notes: + +The script uses display values for priorities, so it’s easy to read. + +If you have a large number of incidents, consider adding query filters (e.g., gr.addActiveQuery()) to improve performance. + +Can be modified to count other fields, like category, assignment group, or state. From df745e6bc258b5170bbdf48bee0fcefa9a91ca49 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Sun, 19 Oct 2025 21:09:33 +0530 Subject: [PATCH 2/2] Create Incident Count on Priority Script.js --- .../Incident Count on Priority Script.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Get incident count based on priority/Incident Count on Priority Script.js diff --git a/Server-Side Components/Background Scripts/Get incident count based on priority/Incident Count on Priority Script.js b/Server-Side Components/Background Scripts/Get incident count based on priority/Incident Count on Priority Script.js new file mode 100644 index 0000000000..206553dbe2 --- /dev/null +++ b/Server-Side Components/Background Scripts/Get incident count based on priority/Incident Count on Priority Script.js @@ -0,0 +1,16 @@ + var gr = new GlideRecord('incident'); + gr.query(); + + var priorities = {}; + + while (gr.next()) { + var priority = gr.getDisplayValue('priority') || 'No Priority Set'; + if (!priorities[priority]) { + priorities[priority] = 0; + } + priorities[priority]++; + } + + for (var p in priorities) { + gs.info('Priority: ' + p + ' | Count: ' + priorities[p]); + }