- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 03:16 AM
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.
Please help me on this issue.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 03:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 03:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 04:24 AM
Hi Akash
For loop resolved my issue. Also chooseWindow works for glideAggregate.
Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 03:22 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 03:24 AM
Hi Madhusudhan
Why don't you break the loop after count reaches more than 5?
Thanks
Abhinandan