what is the glide aggregate function?how to use

preddy1
Giga Expert

what is the glide aggregate function?how to use

1 ACCEPTED SOLUTION

Hi 

Please try it in the background script :-

 

var count =new GlideAggregate('incident');
count.addAggregate('COUNT');
count.query();
var incidents =0;
if(count.next())

{

incidents = count.getAggregate('COUNT');
gs.print(incidents);
}

Copy paste this code in Background script.

See below :-

 

find_real_file.png

 

find_real_file.png

find_real_file.png

Regards,

 

Omkar Mone.

www.dxsherpa.com

View solution in original post

23 REPLIES 23

Deepak Ingale1
Mega Sage

Please find below link

 

The GlideAggregate class is an extension of GlideRecord and allows database aggregation (COUNT, SUM, MIN, MAX, AVG) queries to be done. This can be helpful in creating customized reports or in calculations for calculated fields. 

 

https://docs.servicenow.com/bundle/jakarta-application-development/page/script/glide-server-apis/con...

 

Note: Please mark reply as correct if it has answered your question

where we need to wright these scripts to get the count of a table

Sindhu B1
Giga Expert

Hi ,

The GlideAggregate class is an extension of GlideRecord and allows database aggregation (COUNT, SUM, MIN, MAX, AVG) queries to be done. This can be helpful in creating customized reports or in calculations for calculated fields.

GlideAggregate examples

count of the number of records

var count = new GlideAggregate('incident');
count.addAggregate('COUNT');
count.query();
var incidents = 0;
if(count.next()) 
   incidents = count.getAggregate('COUNT');



 count of the incidents that were open

var count = new GlideAggregate('incident'); count.addQuery('active','true'); count.addAggregate('COUNT'); count.query(); var incidents = 0; if(count.next()) incidents = count.getAggregate('COUNT');

open incidents by category
var count = new GlideAggregate('incident');
count.addQuery('active','true');
count.addAggregate('COUNT','category');
count.query();
while(count.next()){
  var category = count.category;
  var categoryCount = count.getAggregate('COUNT','category');
  gs.log("there are currently "+ categoryCount +" incidents with a category of "+ category);}

https://docs.servicenow.com/bundle/jakarta-application-development/page/script/glide-server-apis/con...


Please mark it as correct
Regards,
Sindhu
 
 

where should i wright these scripts?and the entire script i need to wright that you have given?