difference between getRowCount VS getaggregate('COUNT')

Sagar_pawar
Tera Contributor

Hello All,

I do not understand what the difference is between getRowCount and getAggregateCount. can anyone please guide me on this?

Thank You.

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @Sagar_pawar ,

getRowCount - Used to get the Row count but it is not recommanded for any aggregate operation use GlideAggregate.

GlideAggregate
GlideAggregate used to do database aggregation operations(Count, Min, max, sum, AVG, etc..)

Refer below link for GlideAggregate methods with examples.

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideAggregateAPI#r_Gl...

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

6 REPLIES 6

RaghavSh
Kilo Patron

Glide Aggregate is a service-now class for mathematical functions like sum, count min , max etc. getAggregateCount is the recommended function.

getRowCount() is used with glideRecord class but that is not recommended by servicenow. for any mathematical operations glideAggregate is the recommended way, even if they return same results.

 

Refer: https://www.servicenow.com/community/developer-forum/server-side-code-should-not-use-gliderecord-and... 


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

Community Alums
Not applicable

Hi @Sagar_pawar 

 

You can either use the getRowCount() method from GlideRecord, or just use GlideAggregate.

Using GlideRecord to count rows of records will cause scalability issues as tables can grow over time. This method retrieves every record and counts them. GlideAggregate retrieves the data from the actual MySQL database that's built in to ServiceNow, which is much faster when it comes to performance.

The 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

 

If you find this answer helpful, please mark it as helpful and accept the solution.

Edgar10
Tera Guru

Hi Abhi ,

 

getRowCount is used in GlideRecord while getAggregateCount is use in GlideAggregate .

 

Servicenow promotes using GlideAggregate as it is much faster then using GlideRecord then getRowCount.

Also if you used getRowCount it might affect the upgrade score in your instance as this will be pointed out when you perform instance scanning .

 

Hope this helps you.

 

Regards,

Edgar

Vasantharajan N
Giga Sage
Giga Sage

Blue background in the screenshot is the Object used.

Yellow background is the data available in the objects (gr for GlideRecord & ag for GlideAggregate)

VasantharajanN_1-1671776396450.png


Thanks & Regards,
Vasanth