Anyone know how to select the top 5 rows using a gliderecord query?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2012 10:03 AM
Anyone know how to select the top 5 rows using a gliderecord query? Trying to avoid a loop counter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2012 10:33 AM
I haven't tried this yet, but would this work? I am not sure if the value is sysparm_rowcount exactly.
var gr = new GlideRecord("table");
gr.addQuery('sysparm_rowcount', '<=', '5');
gr.query();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2012 10:45 AM
You can add an orderby/orderbydesc query and setlimit to get a top five.
var gr = new GlideRecord('table');
gr.orderByDesc('sys_created_on');
gr.setLimit(5);
gr.query();
Would give you the 5 most recently created records on a table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2020 10:13 AM
Yup, this works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2012 10:46 AM
That did not work, I also tried "rowcount" and "row_count".
This is in a UI Macro so it mite be I am not escaping the '<' properly.