Skip to content

Commit a0769da

Browse files
authored
Initial create script.js
1 parent 24da1e0 commit a0769da

File tree

1 file changed

+45
-0
lines changed
  • Core ServiceNow APIs/GlideAggregate/Count open Incidents per Priority and State using GlideAggregate

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*Going to define the Incident Closed and Canceled state since we dont want those records as part of our query.
3+
*Also going to leverage the IncidentStateSNC script from ServiceNow
4+
*/
5+
6+
/*
7+
*Going to define the Incident Closed and Canceled state since we dont want those records as part of our query.
8+
*/
9+
var incident_close = IncidentStateSNC.CLOSED;
10+
var incident_canceled = IncidentStateSNC.CANCELED;
11+
var incident_state_query = incident_close + "," + incident_canceled;
12+
13+
/*
14+
*Creating the Incident State value object that will house the correct incident state since we are working from the Task table.
15+
*Leveraging the IncidentStateSNC script from ServiceNow to get the values that they should be
16+
*/
17+
var incident_states = {
18+
'1':'New',
19+
'2':'In Progress',
20+
'3':'On Hold',
21+
'6':'Resolved',
22+
'7':'Closed',
23+
'8':'Canceled'
24+
};
25+
26+
//Going to create the GlideAggregate object
27+
var ga = new GlideAggregate('task');
28+
ga.addQuery('state', 'NOT IN', incident_state_query); //Going to exclude the canceled and closed incidents
29+
ga.addQuery('sys_class_name', 'incident'); //Since working on the Task table need to grab only Incident records with task type
30+
ga.groupBy('state');
31+
ga.groubBy('count');
32+
ga.addAggregate('COUNT');
33+
ga.query()
34+
35+
gs.info('The following is a list of Open Incident records');
36+
37+
while (ga.next()) {
38+
39+
var priorityValue = ga.getDisplayValue('priority');
40+
var state = ga.getValue('state');
41+
var count = ga.getValue('COUNT');
42+
43+
gs.info("There are a total of: " + count + " Incidents with a priority of " + priorityValue + " and in a state of " + incident_staates[state]);
44+
45+
}

0 commit comments

Comments
 (0)