- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 08:47 AM
Hi,
simple question here from someone just getting started with ServiceNow:
The code example for the getRowCount() method (GlideRecord API) uses the method without first querying the table with query().
Elsewhere (e.g. in the ServiceNow Admin learning plan) it has query() used before:
And the example below seems to be right because if I use getRowCount() without query() I always get a count of 0 (which would make the upper coding example pointless).
Am I missing something here or is the API reference wrong?
Thanks a bunch
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 09:00 AM
Hey,
First of all welcome to the world of SN
And I would like to share my experience with getRowCount() and there will so many things that you will be exploring regarding the same.
The first screenshot is not valid, first of all no query statement there which basically executes your database query and throw out the result, which is not happening here. Also, FYI GlideRecords are not allowed to be used at Client side scripting and only in Server side
Talking about 2nd screenshot, yes the code looks alright and this is how it is supposed to work with query() function after GlideRecord call.
Moreover, once you dig down further getRowCount is also not best practice and we should be using GlideAggregate for such basic mathematical like Count, Sum, Average etc
Ref link:
https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
Please let me know, if it answers your query, will be more than glad to share more insights!
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 09:00 AM
Hey,
First of all welcome to the world of SN
And I would like to share my experience with getRowCount() and there will so many things that you will be exploring regarding the same.
The first screenshot is not valid, first of all no query statement there which basically executes your database query and throw out the result, which is not happening here. Also, FYI GlideRecords are not allowed to be used at Client side scripting and only in Server side
Talking about 2nd screenshot, yes the code looks alright and this is how it is supposed to work with query() function after GlideRecord call.
Moreover, once you dig down further getRowCount is also not best practice and we should be using GlideAggregate for such basic mathematical like Count, Sum, Average etc
Ref link:
https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
Please let me know, if it answers your query, will be more than glad to share more insights!
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 09:04 AM
Thanks for the fast response. Yeah, the documentation says that GlideAggregate is the way to go in a production environment.
I was just confused because the upper screenshot is straight from the official API reference. Thanks for clearing this up!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 09:22 AM
Always!
Feel free to reach out and also share new things that you explore!
Aman Kumar