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 do dot walking in groupBy() method.

Charan123
Tera Expert

Hi,
For Example: By doing GlideRecord on incident table, i want to filter records groupby assignment group managers

 

var agg = new GlideAggregate('incident');

agg.addQuery('active=true');

agg.groupBy('assignment_group.manager');

agg.query();

While(gr.next){

}

For above code, result showing empty.

 

Could you please suggest on this.

 

Thanks!!

3 REPLIES 3

Sagar Pagar
Tera Patron

Hi @Charan123,

 

Take a look at this article. It might help you on achieve it:

https://hi.service-now.com/kb_view.do?sysparm_article=KB0745198

 

 

 

var agg = new GlideAggregate('incident');
agg.addQuery('active=true');
agg.addAggregate('COUNT', 'assignment_group.manager');
agg.orderByAggregate('COUNT' , 'assignment_group.manager');
agg.query();
while(agg.next()){
gs.info("Sagar: " + agg.getAggregate('COUNT', 'assignment_group.manager'));

}

 

 

 

 

Thanks,
Sagar Pagar

 

The world works with ServiceNow

Hi @Sagar Pagar 

Thanks for reply

I need manager sys_id and will use in another table

 

Hi @Charan123,

Please use below script-

var agg = new GlideAggregate('incident');
agg.addQuery('active=true');
agg.groupBy('assignment_group.manager');
agg.setLimit(10)
agg.query();

while(agg.next()){
gs.info(agg.getValue('assignment_group.manager'))
}

 

Please try running above script in background, you ll get sys_id of manager.


 

Please mark the answer as correct, If I answered your query. It will be helpful for others who are looking for similar questions.

Regards
Saurabh


Thanks and Regards,

Saurabh Gupta