What is the difference between GlideAggregrate vs GetRowCount() in servicenow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 04:33 AM
Hi All,
Please tell me the difference between GlideAggregrate vs GetRowCount() in servicenow
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 04:38 AM
GlideRecord: 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.
example:
gets a count of the number of records in a table:
var count = new GlideAggregate('incident');
count.addAggregate('COUNT');
count.query();
var incidents = 0;
if(count.next())
incidents = count.getAggregate('COUNT');
GetRowCount(): Retrieves the number of rows in the query result.
Example
var gr = new GlideRecord('incident')
gr.query();
gs.info("Records in incident table: " + gr.getRowCount());
Thanks,
Shrutika Surwade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 04:39 AM
Hi,
GlideAggregate - getRowCount()
Retrieves the number of rows in the GlideAggregate object. Refer to https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_ScopedGlideAggregateGetRowCount
GlideRecord - getRowCount()
Retrieves the number of rows in the query result.. Refer to https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_ScopedGlideRecordGetRowCount
In the links above, you will find some example.
I would also suggest to read the solution provided in the thread below, it will clarify your doubt:
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
Thank you
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 04:40 AM
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.
example-
ar 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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 04:42 AM
Hi Shilpi,
- GlideAggregate - If you're just counting records.
- getRowCount() - If you need to do something ELSE to the records, like updates, deletes, etc.
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.