GlideAggregate

All the GlideAggregate

Last modified 2025-06-20

Jace Benson

Table of content
  1. addAggregate
  2. getAggregate
  3. getAggregateEncodedQuery
  4. orderByAggregate
  5. setGroup
  6. next
  7. getRowCount
  8. getAggregateEncodedQuery
  9. addAggregate
  10. query
  11. getTableName
  12. getCategory
  13. orderBy
  14. orderByDesc
  15. hasNext
  16. groupBy
  17. getEncodedQuery
  18. addNotNullQuery
  19. orderByAggregate
  20. addNullQuery
  21. getValue
  22. setGroup
  23. addEncodedQuery
  24. setCategory
  25. addQuery

The scoped GlideAggregate class is an extension of GlideRecord and allows database aggregation (COUNT, SUM, MIN, MAX, AVG) queries to be done. This can be helpful in creating customized reports or in calculations for calculated fields. The GlideAggregate class works only on number fields. Since currency fields are strings, you can't use the GlideAggregate class on currency fields

Official Docs: GlideAggregate

The scoped GlideAggregate class is an extension of GlideRecord and allows database aggregation (COUNT, SUM, MIN, MAX, AVG) queries to be done. This can be helpful in creating customized reports or in calculations for calculated fields. The GlideAggregate class works only on number fields. Since currency fields are strings, you can't use the GlideAggregate class on currency fields

addAggregate

Adds an aggregate

var count = new GlideAggregate('io_set_item');
//parm1: COUNT, MIN, MAX, parm2: field
count.addAggregate('COUNT', 'variable_set');
count.query();
while (count.next()) {
   var set = count.variable_set.getDisplayValue();
   var setCount = count.getAggregate('COUNT', 'variable_set');
   var message = "The are currently " + setCount;
   message += " items with a variable set of " + set;
   gs.print(message);
}
/*Output
[0:00:00.345] Script completed in scope global: script
*** Script: The are currently 1 items with a variable set of Generic Request
*** Script: The are currently 154 items with a variable set of Request For
*/

getAggregate

Gets an aggregate

var count = new GlideAggregate('io_set_item');
//parm1: COUNT, MIN, MAX, parm2: field
count.addAggregate('COUNT', 'variable_set');
count.query();
while (count.next()) {
   var set = count.variable_set.getDisplayValue();
   var setCount = count.getAggregate('COUNT', 'variable_set');
   var message = "The are currently " + setCount;
   message += " items with a variable set of " + set;
   gs.print(message);
}
/*Output
[0:00:00.345] Script completed in scope global: script
*** Script: The are currently 1 items with a variable set of Generic Request
*** Script: The are currently 154 items with a variable set of Request For
*/

getAggregateEncodedQuery

Gets an aggregate’s encoded query.

orderByAggregate

Orders a-z an aggregate.

setGroup

Sets whether the results are to be grouped

next

Moves to the next record in the GlideAggregate

getRowCount

Retrieves the number of rows in the GlideRecord

getAggregateEncodedQuery

Gets the query necessary to return the current aggregate

addAggregate

Adds an aggregate

query

Issues the query and gets the results

getTableName

Retrieves the table name associated with this GlideRecord

getCategory

Gets the optional category value of the query

orderBy

Orders the aggregates using the value of the specified field. The field will also be added to the group-by list

orderByDesc

Sorts the aggregates into descending order based on the specified field

hasNext

Determines if there are any more results in the GlideAggregate

groupBy

Provides the name of a field to use in grouping the aggregates. May be called numerous times to set multiple group fields

getEncodedQuery

Retrieves the encoded query

addNotNullQuery

Adds a NOT NULL query to the aggregate

orderByAggregate

Sorts the aggregates based on the specified aggregate and field

addNullQuery

Adds a NULL query to the aggregate

getValue

Gets the value of a field

setGroup

Sets whether the results are to be grouped

addEncodedQuery

Adds a query to the aggregate. Adds an encoded query to the other queries that may have been set for this aggregate

setCategory

Sets the value of category for the query

addQuery

Adds a query to the aggregate