- 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:56 AM
Hi Madhusudan,
Instead count.setLimit(5) use count.chooseWindow(1,5);
I think setLimit won't work for glide Aggregate just now i tried i got the solution with chooseWindow(first,last).
For more info:
The chooseWindow(first,last) method lets you set the first and last row number that you want to retrieve and is typical for chunking-type operations. The rows for any given query result are numbered 0..(n-1), where there are n rows. The first parameter is the row number of the first result you'll get. The second parameter is the number of the row after the last row to be returned. In the example below, the parameters (10, 20) will cause 10 rows to be returned: rows 10..19, inclusive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2016 04:26 AM
Hi Midhun
Thank you very much for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 01:39 AM
Thank you, this has resolved also my issue, loop has helped me to learn how to set limit to max results to be returned from database using aggregate
/Petr