- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 02:25 AM
Hi All,
I have a query.
currently in our system we have gliderecord in script which basically counts using getrowcount and also deletes junk records .
We want to usse glideagrregate to count, so this entire functionality using glideagrregate can this be achieved?
Thanks,
Abhinab
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 05:51 AM
If you are deleting records, then there is no performance gained by using GlideAggregate. They are going to do the same thing in the end. The only performance gained is using GlideAggregate's count over GlideRecord's getRowCount() for simply count operations.
My recommendation is to use GlideRecord, getRowCount() to count the records and deleteRecord() to delete them in the same server side script. If you use GlideAggregate with deleteRecord(), you're going to confuse someone somewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 04:39 AM
Hi Ahinab,
- var count = new GlideAggregate('incident');
- count.query(); // Issue the query to the database to get all records
- while (count.next()) {
- count.deleteRecord();
- gs.print(count.number);
- }
- gs.print(count.getRowCount());
You can use both getRowCount() and deleteRecord() in GlideAggregate.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 05:25 AM
While deleteRecord() is not documented, I know that GlideAggregate shares many of the same methods (like addQuery()) as GlideRecord. Your solution is basically the same as GlideRecord, so there's not counting going on in your example.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 05:31 AM
I just did some testing and have a strong suspicion that GlideAggregate is an extension of GlideRecord. The query setup is the same and even methods like getRowCount() and deleteRecord() are available to GlideAggregate. Although, I don't recommend using them that way as there is no direct benefit.
Can you describe the problem you are trying to solve? That would point us in the direction of a proper technical solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 05:44 AM
My requirement is that in our audit /Servicenow inspection , Servicneow provided the update that performance related to change certain codes. the getRowcount to count records used in scripts to GlideAggregate.
But there is a place , you can say multiple script (CS , BR, SInclude) where getRowcount is used) So ia m not sure if i should use it as , using GlideAgrregate class I am able to get count but not delete the records , in that case i need to use Sergiu's solution.
But considering both scnario which is better , USe getRowCount as is , or create two objects as Sergiu suggested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 06:07 AM
If you do it once, then yes, getRowCount() is much easier.
But if would have needed to do many times it in a loop, then getRowCount is about 20 times slower than GlideAggregate, so for large amount of records it can cause significant delay, see below example:
var gr = new GlideRecord('sys_metadata');
gr.query();
gs.print(gr.getRowCount());
[0:00:00.732] Script completed in scope global: script
*** Script: 243635
var gr = new GlideAggregate('sys_metadata');
gr.addAggregate('COUNT');
gr.query();
if(gr.next())
gs.print(gr.getAggregate('COUNT'));
[0:00:00.035] Script completed in scope global: script
*** Script: 243635
700ms on getRowCount vs 35ms on GlideAggregate