Question in Background script

Srini19
Tera Contributor

Hi 

 

I a m trying to execute the below script and getting NAN for assignment group, plesae advise

 

This Query is to getting the list of incident as per assignment group 

 

var gr= new GlideAggregate('incident');
gr.addQuery('active',true);
gr.addAggregate('COUNT');
gr.groupBy('assignment_group.name');
gr.query();


while(gr.next())
{
var countof=gr.getAggregate('COUNT');
gs.print(+gr.getDisplayValue('assignment_group.name'));
gs.print("count of assignment group is" +countof);
}

Query result:

 

Srini19_0-1727111368191.png

 

1 ACCEPTED SOLUTION

Sai_Charan_K
Kilo Sage

Hi @srininaidu ,

Please find the below script that works for me. 

var gr= new GlideAggregate("incident");
gr.addQuery("active",true);
gr.addAggregate("COUNT");
gr.groupBy("assignment_group");
gr.query();
while(gr.next()){
	var countOf=gr.getAggregate("COUNT");
	var groupName=gr.getDisplayValue("assignment_group");
	gs.print(countOf);
	gs.print(groupName);
}


Please find the screenshot attached below :

Charan27_0-1727113292438.png

 Please mark this answer as "Helpful" and correct if this answer helped you in anyway.

Thanks and Regards, 
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You have an errant + in the gs.print command, and either use gr.getValue('name') or gr.getDisplayValue('assignment_group')

Sai_Charan_K
Kilo Sage

Hi @srininaidu ,

Please find the below script that works for me. 

var gr= new GlideAggregate("incident");
gr.addQuery("active",true);
gr.addAggregate("COUNT");
gr.groupBy("assignment_group");
gr.query();
while(gr.next()){
	var countOf=gr.getAggregate("COUNT");
	var groupName=gr.getDisplayValue("assignment_group");
	gs.print(countOf);
	gs.print(groupName);
}


Please find the screenshot attached below :

Charan27_0-1727113292438.png

 Please mark this answer as "Helpful" and correct if this answer helped you in anyway.

Thanks and Regards, 
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India

Srini19
Tera Contributor

Thanks, its working now