Skip to content

Commit 55d8b4b

Browse files
authored
Count all open incidents per priority (#1819)
* script.js * readme.md * Update readme.md
1 parent d2e9e40 commit 55d8b4b

File tree

2 files changed

+44
-0
lines changed
  • Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority

2 files changed

+44
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Count Open Incidents per Priority Using GlideAggregate
2+
3+
## Overview
4+
This script dynamically calculates the **number of open incidents** for each priority level using **server-side scripting** in ServiceNow.
5+
Priority levels typically include:
6+
+ 1 – Critical
7+
+ 2 – High
8+
+ 3 – Moderate
9+
+ 4 – Low
10+
11+
The solution leverages **GlideAggregate** to efficiently count records grouped by priority. This approach is useful for:
12+
+ Dashboards
13+
+ Automated scripts
14+
+ Business rules
15+
+ SLA monitoring and reporting
16+
17+
---
18+
19+
## Table and Fields
20+
+ **Table:** `incident`
21+
+ **Fields:** `priority`, `state`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(function() {
2+
// Create GlideAggregate object on 'incident' table
3+
var ga = new GlideAggregate('incident');
4+
5+
// Filter only open incidents (state != Closed (7))
6+
ga.addQuery('state', '!=', 7);
7+
8+
// Group results by priority
9+
ga.groupBy('priority');
10+
11+
// Count number of incidents per priority
12+
ga.addAggregate('COUNT');
13+
14+
ga.query();
15+
16+
gs.info('Open Incidents by Priority:');
17+
18+
while (ga.next()) {
19+
var priority = ga.priority.getDisplayValue(); // e.g., Critical, High
20+
var count = ga.getAggregate('COUNT');
21+
gs.info(priority + ': ' + count);
22+
}
23+
})();

0 commit comments

Comments
 (0)