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

where should we see the output of these scripts

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

thanks for your help omkar it is working fine but i want with business rule that i shared the screen shot of busines rule where should we see the output of the result

Hi 

You can add a gs.log() if you want. The thing is GlideAggregate will work, but if you want to see the chaqnges, create a field and then set the value to the field on incident form.

 

Something like this :-

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

{ 

incidents = count.getAggregate('COUNT');
count.setValue('u_new_field',incidents);
}

 

Regards.

 

 

 

Hello preddy

Here is how you can do this

 

 

Create a BR on incident table.

Select before and Query

And in advanced, add below code

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var count = new GlideAggregate('incident');
count.addAggregate("COUNT");
count.query();
var total_incidents = 0;
if(count.next()) {
total_incidents = count.getAggregate("COUNT");
}
gs.addInfoMessage("count of incidents are "+total_incidents);

})(current, previous);

 

This will print the output on incident list.

 

Kindly mark my answer as correct if this helps.