GlideAggregate MAX Returning Multiple Values Instead of a Single Maximum Value

NishmithaS
Tera Contributor

Hi All

I'm testing GlideAggregate with a MAX aggregate

 

var ga = new GlideAggregate('incident');
ga.addAggregate('MAX', 'u_cost');
ga.query();

while (ga.next()) {
    gs.print('MAX=' + ga.getAggregate('MAX', 'u_cost'));
}

Expected result:
MAX=300

Actual result:
MAX= 
MAX=1 
MAX=100 
MAX=200 
MAX=300
The u_cost field is of type Integer.
when i use this
if (ga.next()) {
    gs.print('MAX=' + ga.getAggregate('MAX', 'u_cost'));
}

i get
MAX=​


The aggregate appears to be returning values separately for each u cost value instead of a single MAX value.

Any suggestions on why GlideAggregate is not returning a single MAX value




1 ACCEPTED SOLUTION

Adrian Ubeda
Mega Sage

Hello @NishmithaS , 

Try this:

var ga = new GlideAggregate('incident'); 
ga.addAggregate('MAX', 'u_cost');       
ga.setGroup(false);                    
ga.query();

if (ga.next()) {
    var maxVal = ga.getAggregate('MAX', 'u_cost');
    gs.print('The maximum value is: ' + maxVal);
}
If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

View solution in original post

2 REPLIES 2

Adrian Ubeda
Mega Sage

Hello @NishmithaS , 

Try this:

var ga = new GlideAggregate('incident'); 
ga.addAggregate('MAX', 'u_cost');       
ga.setGroup(false);                    
ga.query();

if (ga.next()) {
    var maxVal = ga.getAggregate('MAX', 'u_cost');
    gs.print('The maximum value is: ' + maxVal);
}
If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Hi @Adrian Ubeda 

 

Thank you