GlideAggregate - addEncodedQuery(String query)

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

Table 1. Parameters
Name Type Description
query String An encoded query string to add to the aggregate.
Table 2. Returns
Type Description
void

Scoped equivalent

To use the addEncodedQuery() method in a scoped application, use the corresponding scoped method: Scoped GlideAggregate - addEncodedQuery(String query).

var agg = new GlideAggregate('incident');
agg.addAggregate('count','category'); 
agg.orderByAggregate('count', 'category'); 
agg.orderBy('category'); 
agg.addQuery('opened_at', '>=', 'javascript:gs.monthsAgoStart(2)'); 
agg.addQuery('opened_at', '<=', 'javascript:gs.monthsAgoEnd(2)'); 
agg.query(); 
while (agg.next()) { 
  var category = agg.category;
  var count = agg.getAggregate('count','category');
  var query = agg.getQuery();  
  var agg2 = new GlideAggregate('incident');   
  agg2.addAggregate('count','category');
  agg2.orderByAggregate('count', 'category');
  agg2.orderBy('category');
  agg2.addQuery('opened_at', '>=', 'javascript:gs.monthsAgoStart(3)');
  agg2.addQuery('opened_at', '<=', 'javascript:gs.monthsAgoEnd(3)');
  agg2.addEncodedQuery(query);
  agg2.query();
  var last = "";
  while (agg2.next()) {
     last = agg2.getAggregate('count','category');      
  }
  gs.log(category + ": Last month:" + count + " Previous Month:" + last);
 
}