🎓 Scenario-Based Question
📌 Use Case: Get the Count of Incidents with Breached SLA
This use case demonstrates how to use GlideAggregate to find the number of incidents whose associated SLAs have been breached.
🛠 Steps to Implement:
- Identify the Data Source
- Table:
task_sla
- Filter:
task.sys_class_name = "incident"
andhas_breached = true
- Table:
- Write the Script
- Use
GlideAggregate
to group and count results efficiently
var breachedSLA = 0; var slaGR = new GlideAggregate("task_sla"); slaGR.addQuery("task.sys_class_name", "incident"); slaGR.addQuery("has_breached", true); slaGR.addAggregate("COUNT"); slaGR.query(); if (slaGR.next()) { breachedSLA = slaGR.getAggregate("COUNT"); } gs.print("Count of incidents with breached SLAs: " + breachedSLA);
- Use
- Run & Verify
- Execute in
Background Scripts
or scheduled script execution - Check system logs for the printed count
- Execute in
💡 Pro Tip:
GlideAggregate
is preferred overGlideRecord
when you only need counts or summaries — it’s faster and uses less memory.- You can extend this query to group by priority, assignment group, or SLA definition for deeper reporting.