File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Core ServiceNow APIs/GlideAggregate/Count All Open Incidents Per Priority Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 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 `
Original file line number Diff line number Diff line change 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+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments