🎓 Scenario-Based Question
📊 Use Case: Get Incident Count Per State
Run this script in Background Scripts to get the count of incidents in each state.
It uses the GlideAggregate
method to group and count incidents by their state.
gs.print("State\t Incident Count"); var inc = new GlideAggregate('incident'); // Uncomment the next line if you want to exclude "New" state incidents (state=1) from the result // inc.addEncodedQuery('state!=1^ORstate=NULL'); inc.addAggregate('COUNT', 'state'); inc.query(); while (inc.next()) { gs.print(inc.state.getDisplayValue() + "\t" + inc.getAggregate('COUNT', 'state')); }
💡 Tips:
- Use
addEncodedQuery
to filter states you want to exclude or include. getDisplayValue()
returns the user-friendly state name instead of the numeric value.- Perfect for generating quick reports or dashboards on incident state distribution.