The CreatorCon Call for Content is officially open! Get started here.

How to query for the latest record in a table?

nehayadav
Kilo Contributor

Hello,

How can I query for the latest record from a table.

thanks!

1 ACCEPTED SOLUTION

Please note that the setLimit(1) will limit the query to only the first record returned by the query and the orderByDesc('sys_created_on') will sort the results based on its created date been the most recent one the first one in the list.



I hope this helps



Thanks,


Berny


View solution in original post

10 REPLIES 10

Thanks Berny! This is exactly what I was looking for.



-Neha


You're welcome!


How can I call this method from report condition builder?

Hari Munagala
Kilo Contributor

Hi,

How to print my latest 10 incidents by written background script

Hi Hari,

 

See changes in bold below for your requirement:

 

var gr = new GlideRecord ('incident');

gr.orderByDesc('sys_created_on');


gr.setLimit(10);


gr.query();


while (gr.next()){


gs.print (gr.number + ' - ' + gr.sys_created_on);


}