- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 11:29 PM
Hi Friend's,
I would like to know the difference between GlideRecord and GlideAggregate definition and with an examples .
Please give me the quick response
Regards,
Jagadeesh
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 12:13 AM
GlideRecord is used when we need to create, modify or delete records from another table.
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
gs.addInfoMessage(gr.number);
}
All the methods can be checked in docs:
https://docs.servicenow.com/bundle/jakarta-application-development/page/app-store/dev_portal/API_reference/glideRecordScoped/concept/c_GlideRecordScopedAPI.html

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 11:50 PM
hi, dzbht
GlideAggregate is an extenstion of GlideRecord only. Just GlideAggregate is used to perform aggregate functions on the database
and allows database aggregation (COUNT, SUM, MIN, MAX, AVG) queries to be done. Its extremely handy.
Using count row as an example, you have two options: the getRowCount() method from GlideRecord, or GlideAggregate. Using GlideRecord to count rows can cause scalability issues as tables grow over time, because it retrieves every record with the query and then counts them. GlideAggregate gets its result from built-in database functionality, which is much quicker and doesn't suffer from the scalability issues that GlideRecord does.
This is why GlideAggregate is used.
For example: when you run a database query like select count(*) from table_name, it fetches the record count real quick, but if you run select * from table_name in your database query it will try to fetch whole bunch of database record that would difinietly take time to present the data to you.
Also there is one disadvantage.When using GlideAggregate, you're not able to access the details in a specific record. You need to use GlideRecord for that. So GlideAggregate is good for sums, etc. but not for access to a specific record. Also, if you want to use the OrderBy function, you'll need to add the aggregate first. Example below:
var gr = new GlideAggregate('x_enig_quote_extrm_coverage');
gr.addQuery('parent', quoteSysId);
gr.addAggregate('count', 'coverage_number'); <-- without this line, the code throws an SQL error
gr.orderByAggregate('count', 'coverage_number');
gr.orderBy('coverage_item_number');
gr.addAggregate('sum','premium');
Also, as per the docs: "This can be helpful in creating customized reports or in calculations for calculated fields. GlideAggregation is an extension of GlideRecord and its use is probably best shown through a series of examples."
https://docs.servicenow.com/bundle/jakarta-application-development/page/script/glide-server-apis/concept/c_GlideAggregate.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 12:02 AM
Tq it is really good and also helpful to me ,But i need one more example for GlideRecord

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 12:13 AM
GlideRecord is used when we need to create, modify or delete records from another table.
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
gs.addInfoMessage(gr.number);
}
All the methods can be checked in docs:
https://docs.servicenow.com/bundle/jakarta-application-development/page/app-store/dev_portal/API_reference/glideRecordScoped/concept/c_GlideRecordScopedAPI.html