|
| 1 | +Incident Priority Counter — ServiceNow Script: |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +Purpose / Use Case: |
| 6 | + |
| 7 | +Quickly see how many incidents exist at each priority level (Critical, High, Medium, Low, etc.). |
| 8 | + |
| 9 | +Useful for monitoring workloads or checking data consistency. |
| 10 | + |
| 11 | +Can serve as a template for other field-based analytics in ServiceNow. |
| 12 | + |
| 13 | +How It Works: |
| 14 | + |
| 15 | +Queries all records in the Incident table. |
| 16 | + |
| 17 | +Loops through each record and retrieves the priority field (display value). |
| 18 | + |
| 19 | +Counts how many incidents exist for each priority. |
| 20 | + |
| 21 | +Outputs the results to system logs (gs.info()). |
| 22 | + |
| 23 | +Installation / Usage: |
| 24 | + |
| 25 | +Navigate to System Definition → Scripts – Background. |
| 26 | + |
| 27 | +Paste the script into the editor. |
| 28 | + |
| 29 | +Click Run Script. |
| 30 | + |
| 31 | +Check System Logs → All to see the output in the format: |
| 32 | + |
| 33 | +Priority: Critical | Count: 10 |
| 34 | +Priority: High | Count: 25 |
| 35 | +Priority: Medium | Count: 30 |
| 36 | +Priority: Low | Count: 5 |
| 37 | +Priority: No Priority Set | Count: 2 |
| 38 | + |
| 39 | +Notes: |
| 40 | + |
| 41 | +The script uses display values for priorities, so it’s easy to read. |
| 42 | + |
| 43 | +If you have a large number of incidents, consider adding query filters (e.g., gr.addActiveQuery()) to improve performance. |
| 44 | + |
| 45 | +Can be modified to count other fields, like category, assignment group, or state. |
0 commit comments