I want to print groupby assignmentgroup and with count,numbers as well

ganeshnerni
Tera Contributor

I want to print groupby assignmentgroup and with count,numbers as well

6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @ganeshnerni 

 

You did not give the full details so assuming you are referring to the Incident report.

 

Table: Incident

Report Type : Bar

 

AGLearnNGrow_0-1743281643832.png

 

*************************************************************************************************************
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]

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

Rohit  Singh
Mega Sage

Hi @ganeshnerni ,

 

You can use below script for your use case.

 

var inc_count;
var ga_inc = new GlideAggregate("incident");
ga_inc.addAggregate("COUNT","assignment_group");
ga_inc.query();
while(ga_inc.next())
{
   var c=1;
   inc_count = ga_inc.getAggregate("COUNT","assignment_group");
   if(ga_inc.assignment_group)
   {
   	gs.info("Assignment Group: " + ga_inc.assignment_group.getDisplayValue() + " have " + inc_count + " number of incidents." + ga_inc.number);
   	var gr_inc = new GlideRecord("incident");
   	gr_inc.addQuery("assignment_group",ga_inc.assignment_group);
   	gr_inc.query();
   	while(gr_inc.next())
   	{
	    gs.info("S.No: " + c + " " + gr_inc.number);
		c=c+1;
   	}
   }
   else
   {
	gs.info("Assignment Group is empty and have " + inc_count + " number of incidents.");
	  	var gr_inc = new GlideRecord("incident");
   	gr_inc.addQuery("assignment_group",ga_inc.assignment_group);
   	gr_inc.query();
   	while(gr_inc.next())
   	{
	    gs.info("S.No: " + c + " " + gr_inc.number);
		c=c+1;
   	}
   }
}

 

Refer the snip

 

Output: Incident list view grouped by assignment group, showing the count of incidents for each group and printing the incident number for each assignment group. 

 

RohitSingh_0-1743332898359.png

 

Incident List View Group By Assignment Group

 

RohitSingh_1-1743332967384.png

 

If my response helped, then accept the solution and hit the thumbs up, so that it benefits the future reader and also me for your efforts towards the community.

 

Regards,

Rohit

Hi @ganeshnerni ,

 

Did you check my solution?

 

If helpful then please accept the solution and hit thumbs up so that it benefits future reader.

 

Regards,

Rohit

Hi @ganeshnerni ,

 

Hope you are doing good. Did you check my solution?

 

If my response helped, then accept the solution and hit the thumbs up, so that it benefits the future reader and also me for your efforts towards the community.

 

Regards,

Rohit