diff --git a/Server-Side Components/Background Scripts/Get Outstanding Incidents/README.md b/Server-Side Components/Background Scripts/Get Outstanding Incidents/README.md new file mode 100644 index 0000000000..9e71d20f00 --- /dev/null +++ b/Server-Side Components/Background Scripts/Get Outstanding Incidents/README.md @@ -0,0 +1,5 @@ +# ServiceNow Background Script — Outstanding Incidents Before Current Month (JSON Output) + +This background script retrieves all "active" incidents created before the start of the current month, and outputs the results in JSON format. + +It is useful for reporting involving aging incident records. diff --git a/Server-Side Components/Background Scripts/Get Outstanding Incidents/get-outstanding-incidents.js b/Server-Side Components/Background Scripts/Get Outstanding Incidents/get-outstanding-incidents.js new file mode 100644 index 0000000000..43eb3584db --- /dev/null +++ b/Server-Side Components/Background Scripts/Get Outstanding Incidents/get-outstanding-incidents.js @@ -0,0 +1,26 @@ +var result = []; + var gr = new GlideRecord('incident'); + gr.addQuery('active', true); + var startOfMonth = new GlideDateTime(); + startOfMonth.setDisplayValue(gs.beginningOfThisMonth()); + gr.addQuery('sys_created_on', '<', startOfMonth); + + gr.query(); + + while (gr.next()) { + result.push({ + number: gr.getValue('number'), + short_description: gr.getValue('short_description'), + assigned_to: gr.getDisplayValue('assigned_to'), + sys_created_on: gr.getDisplayValue('sys_created_on'), + state: gr.getDisplayValue('state') + }); + } + + var output = { + total_count: result.length, + generated_on: gs.nowDateTime(), + outstanding_incidents: result + }; + + gs.print(JSON.stringify(output,null,2));