- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2020 01:46 PM
Hello experts,
Can someone please help me to understand if we can update the records using Glideaggreate?
As part of health scan servicenow suggested to use glideaggreate count instead of glideRecord.getRowCount();
While I was testing few script I came across that using glideaggreate count I was not able to update or delete the records
For eg : consider below business rule for example
var gr = new glideRecord('sc_task');
gr.addQuery('active',true);
gr.query();
var count=gr.getRowCount();
If(count >5)
gr.comment = "test";
gr.update();
Will I be able to achieve update /delete and count with glideaggregate?
Kindly suggest
Thank you.
BR,
MEENAL
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2020 03:23 PM
As is written in ServiceNow documentation, there's no update() method in GlideAggregate.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideAggregateScopedAPI#r_ScopedGlideAggregateNext
To update a record, it is necessary to use GlideRecord.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideRecordScopedAPI
It is, however, possible to use GlideAggregate to sum columns and then use GlideRecord to update a record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2020 03:20 PM
Hi
a small mistake in addAggregate() and getAggregate() functions. You need to pass second paramter as the field name on which you need to do aggregate o find count.
addAggregate('COUNT', 'FIELD NAME');
getAggregate('COUNT', 'FIELD NAME');
Hope that Helps!
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2020 03:43 PM
Yes, you are right for database operations GlideRecord has been used. Also, as
By looking at your script I don't see the need for GlideAggregate. As you don't have any condition that is checking for COUNT etc except in the logs you are printing the count. In your case, you can achieve the update using GlideRecord without GlideAggregate.
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2020 03:23 PM
As is written in ServiceNow documentation, there's no update() method in GlideAggregate.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideAggregateScopedAPI#r_ScopedGlideAggregateNext
To update a record, it is necessary to use GlideRecord.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideRecordScopedAPI
It is, however, possible to use GlideAggregate to sum columns and then use GlideRecord to update a record.