GlideAggregate MAX aggregation not working properly.

Community Alums
Not applicable

Hi All,

 

Please check the attached screenshot.

 

In Script1, I am using GlideAggregate groupBy function and then doing the MAX aggregation, its giving me the expected output (maximum value from the set of records which were in that group).

 

In Script2, I am directly aggregating the MAX, its not giving the desired output. If there is no groupBy then, it should consider all the records of the table and give the maximum value. But its giving the minimum value. Can someone please explain me this?

 

Why is MAX aggregation not working without the groupBy?

 

Documentation link:

https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/G...

 

 

SantoshPoudel1_0-1694194517451.png

SantoshPoudel1_1-1694194530968.png

 

1 ACCEPTED SOLUTION

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
You need to make sure it should not be grouped.

Please use below script for the desired result.


var t=new GlideAggregate('incident')
t.addAggregate('max','sys_mod_count');
t.setGroup(false);
t.query();
if(t.next())
gs.info(t.getAggregate('max','sys_mod_count'))

Thanks and Regards,

Saurabh Gupta

View solution in original post

1 REPLY 1

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
You need to make sure it should not be grouped.

Please use below script for the desired result.


var t=new GlideAggregate('incident')
t.addAggregate('max','sys_mod_count');
t.setGroup(false);
t.query();
if(t.next())
gs.info(t.getAggregate('max','sys_mod_count'))

Thanks and Regards,

Saurabh Gupta