Get the number of records in a glide object before setLimit execute in My Approvals widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 03:53 AM
Hi guys,
I'm pretty new to ServiceNow and this might be a daft question but I'm struggling to find a way to get around this issue. I'm working on the Service Portal and been asked to make a few changes to the My approvals widget. The requirement is that I have to add a view all link alongside the number of approvals in the queue, like in My requests/incident widgets. With my limited knowledge in Service now and scripting in general, I decided that the way to do this is to query the glide object in the server script and pass that number to the client script and display on the footer in the format of 'First 10 of 'result from the server script'
To do this I'm using getRowCount(); but the problem is there's a condition that determines the number of records to display on the widget, which is gr.setLimit(5); The dilemma I'm in is that when I use getRowCount I always get what's set in the setLimit, which in this case is five and I cannot move the setLimit below getRowCount as it becomes invalid.
gr.orderByDesc('sys_created_on');
gr.orderByDesc('state');
gr.addQuery("approver", gs.getUserID());
gr.query();
gr.getRowCount());//This works fine but I cannot then set the limit as below.
gr.setLimit(5);
I was wondering if there's a way to achieve both so I could get the correct row count and subsequently set the limit to 5?
Any help is massively appreciated.
Jon.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 05:34 AM
Hi Jon,
If all you want to do is count records, use GlideAggregate to get the number of records. It is scalable.
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=c_GlideAggregateScopedAPI
Then use GlideRecord to retrieve the records with setLimit()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 06:12 AM
Thanks Chuck, That works!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 11:25 AM
Glad to hear it's working for you Jon.
Don't forget, 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.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 02:14 AM
Thanks Chuck, but I couldn't find the option to mark the thread as correct? Wonder if it has anything to do with this being marked as a discussion as opposed to a question?