How to apply Glide aggregate groupby when I'm using GlideFilter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 12:01 PM
Hi Guys,
I working in a code, but it didn't work. I need to use Glidefilter and the result should be grouped by manager, someone know is its possible?
Following my code:
var now_GR = new GlideAggregate('sys_user_group');
now_GR.groupBy("manager"); //If you comment this line the code will work but with the total and not the result grouped by manager as I need.
now_GR.orderByAggregate('COUNT');
now_GR.query();
var condition = 'active=false';
var filter = new GlideFilter(condition, 'filterCondition');
var countResults = 0;
while (now_GR.next()) {
if (filter.match(now_GR, true))
countResults++;
}
gs.info(countResults);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 12:31 PM
Hi,
Can you please explain what it is you want to achieve?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 12:42 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 02:31 PM
Not sure if I follow, could you elaborate some more?
Do you want to find how many groups that has the same manager and that is above the average of having the same manager?
Example,
the groups and managers are
A - Adam
B - Bart
C - Adam
D - Bart
E - Emily
F - Emily
G - Adam
H - Henry
The average manager has 2 groups, but you only want to find those that has more than 2 groups (Adam in this example has 3 groups), correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 01:00 PM - edited 07-27-2023 01:01 PM
Try following script in background and check if its what you want:
var now_GR = new GlideAggregate('sys_user_group');
now_GR.addQuery('manager','!=','');//comment this line if you dont want to consider empty manager records
now_GR.groupBy("manager");
now_GR.addAggregate('COUNT');
now_GR.query();
var condition = 'active=false';
var filter = new GlideFilter(condition, 'filterCondition');
var countResults = 0;
while (now_GR.next()) {
if (filter.match(now_GR, true))
countResults++;
}
gs.info(countResults);
Regards,Sushant Malsure