GlideAggregate

The GlideAggregate class is an extension of GlideRecord and works in a similar way. The difference is that GlideRecord tends to give you database objects whereas GlideAggregate deals in counts and numbers.

We'll take a quick look at how GlideAggregate works:

var counter = new GlideAggregate('incident');counter.addAggregate('COUNT');counter.query();if (counter.next()) {    var noOfIncidents = counter.getAggregate('COUNT');}

This first example will give us the number of incidents in the database and place it in the noOfIncidents field. We can add addQuery lines in exactly the same way we would for GlideRecord if we wanted to reduce the number of incident records we returned.

As well as COUNT, we can also use SUM, MAX, MIN, and ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.