1

var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT');
ga.groupBy('state'); // Group by the state field
ga.query();
while (ga.next()) {
var state = ga.getDisplayValue('state');
var count = ga.getAggregate('COUNT');
gs.info('State: ' + state + ', Count: ' + count);
}

How can I retrieve the total number of incidents categorized by state in ServiceNow
Working Code Answered question October 3, 2024