diff --git a/Server-Side Components/Background Scripts/Generate Report in Logs/readme.md b/Server-Side Components/Background Scripts/Generate Report in Logs/readme.md new file mode 100644 index 0000000000..10921555be --- /dev/null +++ b/Server-Side Components/Background Scripts/Generate Report in Logs/readme.md @@ -0,0 +1,2 @@ +This script is used to generate quick, data-driven summaries directly in the system logs, without the need to create or view a ServiceNow report. +It’s helpful for Getting quick record counts (by state, priority, assignment group, etc.) diff --git a/Server-Side Components/Background Scripts/Generate Report in Logs/script.js b/Server-Side Components/Background Scripts/Generate Report in Logs/script.js new file mode 100644 index 0000000000..cad77d65c7 --- /dev/null +++ b/Server-Side Components/Background Scripts/Generate Report in Logs/script.js @@ -0,0 +1,40 @@ +// Script: Generate Report in Logs +// Author: Bhavya +// Purpose: Print summary counts for incidents in the system logs + +(function() { + gs.print("=== Incident Summary Report ==="); + + // Total number of incidents + var total = new GlideAggregate('incident'); + total.addAggregate('COUNT'); + total.query(); + total.next(); + gs.print("Total Incidents: " + total.getAggregate('COUNT')); + + // High Priority incidents + var high = new GlideAggregate('incident'); + high.addQuery('priority', 1); + high.addAggregate('COUNT'); + high.query(); + high.next(); + gs.print("High Priority Incidents: " + high.getAggregate('COUNT')); + + // Active incidents + var active = new GlideAggregate('incident'); + active.addQuery('active', true); + active.addAggregate('COUNT'); + active.query(); + active.next(); + gs.print("Active Incidents: " + active.getAggregate('COUNT')); + + // Resolved incidents + var resolved = new GlideAggregate('incident'); + resolved.addQuery('state', 6); // Resolved + resolved.addAggregate('COUNT'); + resolved.query(); + resolved.next(); + gs.print("Resolved Incidents: " + resolved.getAggregate('COUNT')); + + gs.print("=== End of Report ==="); +})();