File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Server-Side Components/Background Scripts/Get Outstanding Incidents Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 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 ) ) ;
You can’t perform that action at this time.
0 commit comments