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.

Group by on multiple columns

Tarasingh26
Tera Expert

Hi All,

 

I have one requirement to group by records on multiple columns and push latest record number into array form each group by. I am trying to accomplish using below script. It is not throwing error but also not displaying any record. Could someone help me if worked on similar kind of requirement.

 

var potentialEntries=[];
var duplicateCheck= new GlideAggregate('sn_risk_advanced_impact');
duplicateCheck.addAggregate('COUNT');
duplicateCheck.groupBy('u_gl_account');
duplicateCheck.groupBy('cost_centre');
duplicateCheck.groupBy('impact_type');
duplicateCheck.query();

while(duplicateCheck.next())
{
var entryNumber=duplicateCheck.number;
var latestNumber= new GlideRecord('sn_risk_advanced_impact');
latestNumber.addQuery('number',entryNumber);
latestNumber.setLimit(1);
latestNumber.orderByDesc('sys_created_on');
latestNumber.query();


if(latestNumber.next())

{
potentialEntries.push(latestNumber.getValue('number'));
}


}
gs.print(potentialEntries);

 

 

Thanks,

Tara Singh

1 REPLY 1

Samaksh Wani
Giga Sage

Hello @Tarasingh26 

 

Plz refer the below link for reference

 

https://www.servicenow.com/community/developer-forum/glideaggregate-grouping-by-multiple-columns/m-p...

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh