Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to get the caller and number of incidents who submitted more

sivanagalakshmi
Tera Contributor

Hi,

we are trying to print only the caller and number of incidents who have submitted more using below script

help us how to compare the elements with in array.

 

below is my code

var highestCount=[];
var gr = new GlideAggregate('incident');
gr.groupBy('caller_id');
gr.addAggregate('COUNT', 'caller_id');
gr.orderByAggregate('count','caller_id');
gr.query();
while(gr.next())
{
   
highestCount.push(gr.getAggregate('COUNT','caller_id'));


}
gs.print(highestCount);
// for(var i=0; i<=highestCount.length;i++){
//  gs.print(highestCount[i]);
//  for(var j=i+1;j<=highestCount.length-1; j++){
//          gs.print(highestCount[j]);

// if(highestCount[i] > highestCount[j]){
// gs.print(gr.getDisplayValue('caller_id')+'has '+''+  gr.getAggregate('COUNT','caller_id'));

// }

//  }
// }
 




1 REPLY 1

Mark Manders
Giga Patron
var highestCount = [];
var callerList = [];
var gr = new GlideAggregate('incident');
gr.groupBy('caller_id');
gr.addAggregate('COUNT', 'caller_id');
gr.orderByAggregate('COUNT', 'caller_id');
gr.query();
while (gr.next()) {
    var count = gr.getAggregate('COUNT', 'caller_id');
    var caller = gr.getValue('caller_id');
    highestCount.push(parseInt(count, 10));
    callerList.push(caller);
}
var maxCount = Math.max(...highestCount);
for (var i = 0; i < highestCount.length; i++) {
    if (highestCount[i] === maxCount) {
        gs.info(callerList[i] + ' has ' + highestCount[i] + ' incidents');
    }
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark