GlideAggregate Query

madhusudanshett
Kilo Contributor

Hello Everyone

I am using the following code to display CI and their count from Incident table.

var count = new GlideAggregate('incident');

count.addNotNullQuery('cmdb_ci');

count.addAggregate('COUNT', 'cmdb_ci');

count.orderByAggregate('COUNT', 'cmdb_ci');

//count.setLimit(limit);

count.query();

while (count.next()) {

var ci = count.cmdb_ci;

var incCount = count.getAggregate('COUNT', 'cmdb_ci');

gs.log("CI: "+ci.getDisplayValue());

gs.log("Count: "+incCount);

}

It gives me the correct output. But I want to display only first 5 CI and their count.

I think setLimit doesnt work here.

ChrisB

b-rad

ctomasi

Please help me on this issue.

Thanks in advance.

1 ACCEPTED SOLUTION

akashsrm100
Kilo Guru

for(var i=0; i<5;i++)


{


if(count.next()) {


var ci = count.cmdb_ci;


var incCount = count.getAggregate('COUNT', 'cmdb_ci');


gs.log("CI: "+ci.getDisplayValue());


gs.log("Count: "+incCount);


}


}


Hope this can work


Ps hit like helpful If helps/correct


View solution in original post

7 REPLIES 7

akashsrm100
Kilo Guru

for(var i=0; i<5;i++)


{


if(count.next()) {


var ci = count.cmdb_ci;


var incCount = count.getAggregate('COUNT', 'cmdb_ci');


gs.log("CI: "+ci.getDisplayValue());


gs.log("Count: "+incCount);


}


}


Hope this can work


Ps hit like helpful If helps/correct


Hi Akash



For loop resolved my issue. Also chooseWindow works for glideAggregate.



Thank you very much.


Deepa Srivastav
Kilo Sage

Did you try with count.setLimit(5); ?



I haven't read the whole code but will using for loop from I=0 to I<5 ( for(var i=0; i<5;i++) ) help you...?



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Abhinandan Pati
Giga Guru

Hi Madhusudhan



Why don't you break the loop after count reaches more than 5?



Thanks


Abhinandan