Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi @sushantmalsure it worked, but only when the condition field is boolean, I tried the condition with another type and didnt worked.

 

Is possible to fix it?

 

var now_GR = new GlideAggregate('sys_user_group');
now_GR.groupBy("manager");
now_GR.addAggregate('COUNT');
now_GR.query();

var condition = 'parent=c042b0661ba73810b4266572f54bcbf6';
var filter = new GlideFilter(condition, 'filterCondition');


var countResults = 0;
while (now_GR.next()) {
if (filter.match(now_GR, true))
countResults++;

}

gs.info(countResults);

 

 

 

Many thanks.

Can you help me understand your complete requirement? I think I am confused with what you are trying to do..

 

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