Skip to content

Commit 409df5e

Browse files
authored
Feature/Get Outstanding Incidents (#1954)
* Create get-outstanding-incidents.js * Create README.md
1 parent 7758d08 commit 409df5e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ServiceNow Background Script — Outstanding Incidents Before Current Month (JSON Output)
2+
3+
This background script retrieves all "active" incidents created before the start of the current month, and outputs the results in JSON format.
4+
5+
It is useful for reporting involving aging incident records.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var result = [];
2+
var gr = new GlideRecord('incident');
3+
gr.addQuery('active', true);
4+
var startOfMonth = new GlideDateTime();
5+
startOfMonth.setDisplayValue(gs.beginningOfThisMonth());
6+
gr.addQuery('sys_created_on', '<', startOfMonth);
7+
8+
gr.query();
9+
10+
while (gr.next()) {
11+
result.push({
12+
number: gr.getValue('number'),
13+
short_description: gr.getValue('short_description'),
14+
assigned_to: gr.getDisplayValue('assigned_to'),
15+
sys_created_on: gr.getDisplayValue('sys_created_on'),
16+
state: gr.getDisplayValue('state')
17+
});
18+
}
19+
20+
var output = {
21+
total_count: result.length,
22+
generated_on: gs.nowDateTime(),
23+
outstanding_incidents: result
24+
};
25+
26+
gs.print(JSON.stringify(output,null,2));

0 commit comments

Comments
 (0)