- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 10:33 AM
Using 'gr.next()' reads the first record in a glide_collection . But if I want to stat reading the records in reverse order (ie. reading the last record, first) how do I do that? Any suggestion will be appreciated. Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 10:41 AM
You need to use orderByDesc() like below
var gr = new GlideRecord ('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()){
gs.print (gr.number + ' - ' + gr.sys_created_on);
}
Regards,
sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 10:40 AM
You need to use orderByDesc() like below
var gr = new GlideRecord ('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()){
gs.print (gr.number + ' - ' + gr.sys_created_on);
}
Regards,
sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 10:41 AM
You need to use orderByDesc() like below
var gr = new GlideRecord ('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()){
gs.print (gr.number + ' - ' + gr.sys_created_on);
}
Regards,
sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 10:53 AM
Before your query add
gr.orderByDesc('sys_created_on');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 11:00 AM
Hi,
Simply use orderByDesc in your code. here is the sample code to refer.
var gr = new GlideRecord('incident');
gr.orderByDesc(‘number');
gr.query();
if (gr.next()) {
gs.info("Number is" +gr.number);
}
Mark the answer as correct or helpful if this helps.