How to apply Glide aggregate groupby when I'm using GlideFilter

MR Carvalho
Tera Contributor

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);

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Can you please explain what it is you want to achieve?

MR Carvalho
Tera Contributor

Hi @OlaN 

 

Because I to make a calculation to find the percentage above the total per manager.

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?

sushantmalsure
Mega Sage
Mega Sage

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);

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure