- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 02:37 PM
I am trying to do a get call to retrieve the latest 10 records in a incident table.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 09:31 PM
Hi Tom,
setLimit(): Sets the limit for how many records you want to fetch.
var c=0;
var check= new GlideRecord('incident');
check.addQuery('category','software');
check.setLimit(10);
check.query();
while(check.next())
{
c++
gs.print('check the :'+check.number);
}
gs.print('total nnumber of record is:'+c);
OUTPUT
http://wiki.servicenow.com/index.php?title=GlideRecord#setLimit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 04:17 PM
Hey Tom,
It would be good to see your existing code, and have a better idea of what you're looking for, but I'll take a stab at it.
I'm assuming that by "latest 10 records in the incident table", you're referring to the 10 most recently created records. If that's the case, this code should do ya:
var grIncident = new GlideRecord('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();
while (gr.next()) {//do whatever you like, such as push their sys_IDs to an array
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2017 04:38 AM
Hi Timothy,
Good catch - the question inquired how to get the latest incident and to do that sorting descending is required - but sorting on what is an open question.
I kindof missed that until I read your post!
If the reply was informational, please like, mark as helpful or mark as correct!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 04:18 PM
you can user setLimit() function in you GlideQuery to get the 10 records ordering by sys_created_on
var gr = new GlideRecord('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.addQuery();
while(gr.next())
{
// Have you code here.
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 09:31 PM
Hi Tom,
setLimit(): Sets the limit for how many records you want to fetch.
var c=0;
var check= new GlideRecord('incident');
check.addQuery('category','software');
check.setLimit(10);
check.query();
while(check.next())
{
c++
gs.print('check the :'+check.number);
}
gs.print('total nnumber of record is:'+c);
OUTPUT
http://wiki.servicenow.com/index.php?title=GlideRecord#setLimit