GlideAggregate Error: Skip invalid GroupBy condition: ORDERBYundefined

NehaSNOW
Tera Guru

Hi Members,

 

I am running the below GlideAggregate script in the Script Backgroung to get the Count of the Incidents per the State wise.
Issue: - Getting the error: - 
Skip invalid GroupBy condition: ORDERBYundefined
*** Script: NEHA COUNT of Incidents 187
Please suggest.
Script: -
var gaCount = new GlideAggregate('incident');
gaCount.addAggregate('COUNT',gaCount.number);
gaCount.groupBy(gaCount.state);
gaCount.query();

while(gaCount.next()){
gs.info("NEHA COUNT of Incidents "+gaCount.getAggregate('COUNT',gaCount.number));
}
 
Thanks,
Neha Pateria
1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @NehaSNOW ,

try this

var gaCount = new GlideAggregate('incident');
gaCount.addAggregate('COUNT');
gaCount.groupBy('state');
gaCount.query();

while (gaCount.next()) {
    gs.info("NEHA COUNT of Incidents " + gaCount.state.getDisplayValue() + ' ' + gaCount.getAggregate('COUNT'));
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

4 REPLIES 4

Chaitanya ILCR
Kilo Patron

Hi @NehaSNOW ,

try this

var gaCount = new GlideAggregate('incident');
gaCount.addAggregate('COUNT');
gaCount.groupBy('state');
gaCount.query();

while (gaCount.next()) {
    gs.info("NEHA COUNT of Incidents " + gaCount.state.getDisplayValue() + ' ' + gaCount.getAggregate('COUNT'));
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Ankur Bawiskar
Tera Patron
Tera Patron

@NehaSNOW 

your syntax and script for GlideAggregate is wrong.

Use script shared by @Chaitanya ILCR 

More details here

Understanding GlideAggregate 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ravi Gaurav
Giga Sage
Giga Sage

Hi @NehaSNOW 

Can you please try the below please :-

 

var x= new GlideAggregate('incident');
x.addAggregate('COUNT'); 
x.groupBy('state'); 
x.query();

while (x.next()) {
gs.info("NEHA COUNT of Incidents in State " + x.getValue('state') + " : " + x.getAggregate('COUNT'));
}
Output :-
*** Script: NEHA COUNT of Incidents in State 1 : 45
*** Script: NEHA COUNT of Incidents in State 2 : 32

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Vasanthi_L
Tera Contributor
Hi,
 
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT','state');
ga.query();
while (ga.next()){
    gs.info(ga.state.getDisplayValue()  + " " +ga.getAggregate('COUNT','state'));
}
 
Regards
Vasanthi Lankada