Interview Help- New To ServiceNow

vidishaagarwal5
Tera Contributor

Hi Team,

 

I have been asked to write the code align with the Below Image..

I have used glideAggrette.. But state is showing like 2,3 but not showing in display name and this bog space how to give.

My Code :-

var x=new GlideAggregate('incident');
x.addAggregate('COUNT','state');
x.query();
while(x.next()){
gs.print(x.state.+grIncident. getAggregate('COUNT','state'));
}
not getting the below Output

vidishaagarwal5_0-1755766208076.png


@David my Post is always getting in unapproved phase. Help me

 

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hi @vidishaagarwal5 

You need to change the Code to the below code

gs.print('State\\tIncident Count');
var x=new GlideAggregate('incident');
x.addAggregate('COUNT','state');
x.query();
while(x.next()){
gs.print(x.state. getDisplayValue()+'\t'+x. getAggregate('COUNT','state'));
}

This will Help

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


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/

View solution in original post

6 REPLIES 6

Ravi Gaurav
Giga Sage
Giga Sage

Hi @vidishaagarwal5 

You need to change the Code to the below code

gs.print('State\\tIncident Count');
var x=new GlideAggregate('incident');
x.addAggregate('COUNT','state');
x.query();
while(x.next()){
gs.print(x.state. getDisplayValue()+'\t'+x. getAggregate('COUNT','state'));
}

This will Help

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


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/

Bhuvan
Kilo Patron

@vidishaagarwal5 

 

Try this,

 

gs.print('State\tIncident Count');
var incAggregate=new GlideAggregate('incident');
incAggregate.addAggregate('COUNT','state');
incAggregate.addQuery('state','IN','2,3,7');
incAggregate.query();
while(incAggregate.next()){
gs.print(incAggregate.state.getDisplayValue() + '\t' + incAggregate.getAggregate('COUNT','state'));
}

Bhuvan_0-1755795290378.png

Bhuvan_1-1755795330264.png

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

I guess you have added extra Line in query.. which I don't need.. seems to be AI answer.. anyway thank you

@vidishaagarwal5 

 

This is a standard glide aggregate query and not sure why you assume we need AI to answer it.

 

https://developer.servicenow.com/blog.do?p=/post/glideaggregate/

 

As per your requirement, not all the incident states are aggregated and it queries for incidents in status one of 'In Progress, On Hold, Closed'. 

 

Please do not assume without knowing the source. 

 

Thanks,

Bhuvan