GlideAggregate GroupBy giving Incorrect Count

Sumit Pandey1
Kilo Guru
Kilo Guru

Hi All,

When executing the below script, It shows me the count which is different from the count shown in list view with exact same query string! (Going to list view, and applying group by on Manager field).

I have already checked there are no Query Business Rules active on that table.

var myManagerList = [];
var getResourceManagers = new GlideAggregate('sys_user');
getResourceManagers.addEncodedQuery('active=true^company=c7af548d37323100d4e8daa543990e36^managerISNOTEMPTY');
getResourceManagers.addAggregate('COUNT','manager');
getResourceManagers.groupBy('manager');
getResourceManagers.query();  
while (getResourceManagers.next()) 
{
var manager = getResourceManagers.getAggregate('COUNT', 'manager');
myManagerList.push(manager);
}

gs.info('myManager length == '+myManagerList.length); //Output: 3757, List View Count: 3703
1 ACCEPTED SOLUTION

Sumit Pandey1
Kilo Guru
Kilo Guru

Hi All, Thanks for your help. 

The real issue was - "When on a list and performing a 'Group By' action on a column, the row count that appears in the pagination may not match with how many rows are appearing on the page."

More information here - https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0720019

 

Thanks, Sumit

View solution in original post

15 REPLIES 15

Priyanka Vasant
Tera Guru

Hi sumit,

Find the thread that might help you.

https://garrettnow.com/2014/02/28/glideaggregate-examples/

https://community.servicenow.com/community?id=community_question&sys_id=7882c321dbd8dbc01dcaf3231f96193b

 

Regards,

priyanka

Anish Reghu
Kilo Sage
Kilo Sage

Did you copy that encoded query from the list view filter?

Just assuming if it is a case of different filters in list and the script here?

 

LinkedIn

Mark the response helpful or Mark as Correct answer if this helps you reach a solution.

 

Regards,

Anish

Yes, It works on small dataset, but when the record count is huge, let's say 500k records, it starts to give unexpected results.

Anish Reghu
Kilo Sage
Kilo Sage

gs.info('myManager length == 'myManagerList);

For me this fetched the correct result.

 

LinkedIn

Mark the response helpful or Mark as Correct answer if this helps you reach a solution.

 

Regards,

Anish