The CreatorCon Call for Content is officially open! Get started here.

Write a script to print Incident count based on priority.

Parth_S
Tera Contributor

Below is my script which is not giving expected O/P.

 

var gr = new GlideAggregate('incident');
gr.groupBy('priority');
gr.query();
var count = 0;
while(gr.next()){
    gs.info(gr.priority);
    count = count + 1;
    gs.info('Count is ' + count);
}
10 REPLIES 10

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Parth_S 

 

I am not a developer but these links might be helpful

 

https://www.servicenow.com/community/developer-articles/get-last-updated-date-record-using-glideaggr...

 

https://www.servicenow.com/community/developer-forum/script-for-printing-count-of-incidents-per-assi...

 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Abhishek_Thakur
Mega Sage

Hello @Parth_S ,

You can follow the below script, that will work:-

var gr = new GlideAggregate("incident");
gr.groupBy("priority");
gr.addAggregate("COUNT","priority");
gr.query();
while(gr.next()){
	gs.info("Priority is: "+ gr.priority + " and count is: "+ gr.getAggregate("COUNT","priority"));
}

 

Please mark my solution as accepted and give thumbs up, if it helps you.

Regards,

Abhishek Thakur

sanketpatil09
Tera Guru

Hi @Parth_S ,

 

You can use the script below to obtain the count of incidents based on priority.

 

Anand Kumar P
Giga Patron

Hi @Parth_S ,

 

Use below script

 

var agg = new GlideAggregate('incident');

agg.addAggregate('COUNT','priority');

agg.groupBy('priority');

agg.query();

while (agg.next()) {

    var priority = agg.getDisplayValue('priority');

    var incidentCount = agg.getAggregate('COUNT');

    gs.info('Priority: ' + priority + ', Count: ' + incidentCount);

}

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand