GlideAggregate - list multiple counts

Dan Brown2
Kilo Sage

Hi,

I have a report that lists the number of calls created that day using an email script:

The email script is:

var agg = new GlideAggregate('incident');
agg.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
agg.addAggregate('count', 'assignment_group');
agg.orderBy('assignment_group');
agg.query();
while (agg.next()) {
	var assignment_group = agg.assignment_group;
	var count = agg.getAggregate('count', 'assignment_group');
		
	template.print("<li> " + assignment_group.getDisplayValue() + ": Current number of incidents: " + count + "</span></li>");
}

Is it possible to create a different count to these results too?  e.g. the number of incidents resolved by each assignment group?

Cheers,

Dan

 

 

1 ACCEPTED SOLUTION

I have not tested the code...but may be in the following lines will work

 

 

var agg = new GlideAggregate('incident');
agg.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
agg.addAggregate('count', 'assignment_group');
agg.orderBy('assignment_group');
agg.query();
while (agg.next()) {
var assignment_group = agg.assignment_group;
var count = agg.getAggregate('count', 'assignment_group');

var agg2 = new GlideAggregate('incident');
agg2.addEncodedQuery('assignment_group=' +assignment_group+ '^resolved_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
agg2.addAggregate('count', 'assignment_group');
agg2.query();
var r_count = 0;
while (agg2.next()) {

r_count = agg2.getAggregate('count', 'assignment_group');

}
template.print("<li> " + assignment_group.getDisplayValue() + ": Current number of incidents: " + count + ": resolved incidents: " + r_count +"</span></li>");
}

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

3 REPLIES 3

vkachineni
Kilo Sage
Kilo Sage

declare variables for each aggregate and collect them.

var incidents_created_today;

var incidents_resolved_today;

while (agg.next()) {

var assignment_group = agg.assignment_group;

var count = agg.getAggregate('count', 'assignment_group'); 

incidents_created_today = "<li> " + assignment_group.getDisplayValue() + ": Current number of incidents: " + count + "</span></li>"

}

//similarly collect incidents_resolved_today with a different GlideAggregate('incident');

//Finally print to the template

template.print(incidents_created_today + "<br>" +  incidents_resolved_today);

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Dan Brown2
Kilo Sage

Many thanks for the reply.

Will that make 2 lists after each other.

i.e. 

Service Desk opened 10
Deskside opened 3
Network opened 5
Database opened 11
Service Desk resolved 8
Deskside resolved 2
Network resolved 2
Database resolved  1

Would it be possible to have them as:

Service Desk opened 10, resolved 8
Deskside opened 3, resolved 2
Network opened 5, resolved 2
Database opened 11, resolved  1

I have not tested the code...but may be in the following lines will work

 

 

var agg = new GlideAggregate('incident');
agg.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
agg.addAggregate('count', 'assignment_group');
agg.orderBy('assignment_group');
agg.query();
while (agg.next()) {
var assignment_group = agg.assignment_group;
var count = agg.getAggregate('count', 'assignment_group');

var agg2 = new GlideAggregate('incident');
agg2.addEncodedQuery('assignment_group=' +assignment_group+ '^resolved_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
agg2.addAggregate('count', 'assignment_group');
agg2.query();
var r_count = 0;
while (agg2.next()) {

r_count = agg2.getAggregate('count', 'assignment_group');

}
template.print("<li> " + assignment_group.getDisplayValue() + ": Current number of incidents: " + count + ": resolved incidents: " + r_count +"</span></li>");
}

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022