- 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 12:06 PM
Thanks everyone; Sachin_namjoshi, asifnoor and CodingSmith.
Let me redefine my task (this time in details.) I am working on creating a new request form in Service Catalog. On that form, there is a catalog variable 'Request Type'.
When the form is submitted, the workflow will create a corresponding Request Item (RITM). On the RITM, I have put a new catalog variable, 'Reference Number'. I want to increment this 'Reference Number' each time a new request is sumbmitted.
I thought about doing this, by getting a glide_collection of all submitted requests; sort them on 'sys_created_on'; get 'Reference Number' on the last record and generate the next 'Reference Number' by adding one.
Hence, my question is how do I read the last record i glide_collection?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 12:11 PM
Please ignore my response above. I got the solution. It worked exactly the way everyone suggested. Once again, thanks sachin_namjoshi, asignoor and CodingSmith

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 02:15 PM
Do you mind to mark my answer as correct so that others can benefit from same question?
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 08:55 PM
Kindly mark the answer(s) as helpful and correct if it solves so that the question is removed from the unanswered list and it benefit others.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 07:51 PM