Skip to content
Closed
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,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.
Original file line number Diff line number Diff line change
@@ -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]);
}
Loading