What is the difference between GlideAggregrate vs GetRowCount() in servicenow?

Shilpi Sharma2
Tera Contributor

Hi All,

Please tell me the difference between GlideAggregrate vs GetRowCount() in servicenow

 

5 REPLIES 5

Pooja Devkar
Mega Guru

Hello,

getRowCount()

Retrieves the number of rows in the GlideAggregate object.

Example

var count = new GlideAggregate('incident');
  count.addAggregate('MIN', 'sys_mod_count');
  count.addAggregate('MAX', 'sys_mod_count');
  count.addAggregate('AVG', 'sys_mod_count');
  count.groupBy('category');
  count.query();
  gs.info(count.getRowCount());
  while (count.next()) {  
     var min = count.getAggregate('MIN', 'sys_mod_count');
     var max = count.getAggregate('MAX', 'sys_mod_count');
     var avg = count.getAggregate('AVG', 'sys_mod_count');
     var category = count.category.getDisplayValue();
     gs.info(category + " Update counts: MIN = " + min + " MAX = " + max + " AVG = " + avg);
  }

GlideAggregate

GlideAggregate enables you to easily create database aggregation queries.

The scoped GlideAggregate class is an extension of GlideRecord and provides database aggregation (COUNT, SUM, MIN, MAX, AVG) queries. This functionality can be helpful when creating customized reports or in calculations for calculated fields. The GlideAggregate class works only on number fields.

When you use GlideAggregate on currency or price fields, you are working with the reference currency value. Be sure to convert the aggregate values to the user's session currency for display. Because the conversion rate between the currency or price value (displayed value) and its reference currency value (aggregation value) might change, the result may not be what the user expects.

Note: When using an on-premise system, the database server time zone must be set to GMT/UTC for this class to work properly.

GlideAggregate(String tableName)

Creates a GlideAggregate object on the specified table.

Example

 

var count = new GlideAggregate('incident');

Please mark correct & helpful ; if it's useful to you.

Thanks & Regards,

Pooja Devkar