The CreatorCon Call for Content is officially open! Get started here.

calculate same filed value multiple records

____39
Tera Contributor

there a  field u_count which is Integer type, I want to calculate the sum of "u_count " Field of many records, I write this script but is not worked,Does anyone knows why?

var agg = new GlideAggregate('u_work'); 
 agg.addQuery('u_date'> "2023-08-15");   
agg.addAggregate("SUM","u_count");  
agg.query();   
  if (agg.next()) {  
var temp= agg.getAggregate("SUM","u_count");
gs.info(temp);
}
1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage

Hello @____39 

 

You can write this Script :-

 

 

 

var gr = new GlideRecord('u_work');
gr.addEncodedQuery('u_date>javascript:gs.dateGenerate('2023-08-15')');
gr.query();
var sum=0;
while(gr.next()){
sum+=gr.u_count;
}

gs.info(sum);

 

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

View solution in original post

1 REPLY 1

Samaksh Wani
Giga Sage

Hello @____39 

 

You can write this Script :-

 

 

 

var gr = new GlideRecord('u_work');
gr.addEncodedQuery('u_date>javascript:gs.dateGenerate('2023-08-15')');
gr.query();
var sum=0;
while(gr.next()){
sum+=gr.u_count;
}

gs.info(sum);

 

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh