Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,29 @@
# Count open Incidents per Priority and State using GlideAggregate

## Overview
This script will dynamically calculate the **number of open incidents** for each priority level and also give you a total for what
current state the Incident is in using **server-side scripting**
Priority levels typically include:
+ 1 – Critical
+ 2 – High
+ 3 – Moderate
+ 4 – Low

Incident State typically include:
+ New
+ In Progress
+ On Hold
+ Resolved
+ Closed
+ Canceled

The scripting solution leverages **GlideAggregate** to efficiently count records grouped by priority and state. This scripts approach
is useful for:
+ Dashboards
+ Business Rules
+ SLA monitoring and reporting

--
## Table and Fields
+ **Table:** Task
+ **Fields:** Priority, State
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
*Going to define the Incident Closed and Canceled state since we dont want those records as part of our query.
*Also going to leverage the IncidentStateSNC script from ServiceNow
*/

/*
*Going to define the Incident Closed and Canceled state since we dont want those records as part of our query.
*/
var incident_close = IncidentStateSNC.CLOSED;
var incident_canceled = IncidentStateSNC.CANCELED;
var incident_state_query = incident_close + "," + incident_canceled;

/*
*Creating the Incident State value object that will house the correct incident state since we are working from the Task table.
*Leveraging the IncidentStateSNC script from ServiceNow to get the values that they should be
*/
var incident_states = {
'1':'New',
'2':'In Progress',
'3':'On Hold',
'6':'Resolved',
'7':'Closed',
'8':'Canceled'
};

//Going to create the GlideAggregate object
var ga = new GlideAggregate('task');
ga.addQuery('state', 'NOT IN', incident_state_query); //Going to exclude the canceled and closed incidents
ga.addQuery('sys_class_name', 'incident'); //Since working on the Task table need to grab only Incident records with task type
ga.groupBy('state');
ga.groubBy('count');
ga.addAggregate('COUNT');
ga.query()

gs.info('The following is a list of Open Incident records');

while (ga.next()) {

var priorityValue = ga.getDisplayValue('priority');
var state = ga.getValue('state');
var count = ga.getValue('COUNT');

gs.info("There are a total of: " + count + " Incidents with a priority of " + priorityValue + " and in a state of " + incident_staates[state]);

}
Loading