Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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`
Original file line number Diff line number Diff line change
@@ -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);
}
})();
Loading