Query to fetch record having highest value in opened field.

Rajesh M1
Giga Guru

Hi,
How to query a table to fetch a record which has highest value in "opened" field which is a Date/time field?
Thanks in advance.

1 ACCEPTED SOLUTION

harikrish_v
Mega Guru

Add the below 2 lines to your query:-



gr.orderByDesc('opened');


gr.setLimit(1);



Thanks & Regards,


Hari


View solution in original post

4 REPLIES 4

harikrish_v
Mega Guru

Add the below 2 lines to your query:-



gr.orderByDesc('opened');


gr.setLimit(1);



Thanks & Regards,


Hari


Thanks Harikrishnan.


AnishSasidharan
Mega Expert

Hi Raj,



Use OrderByDesc in the glide record.



for eg-



var gr=new GlideRecord('incident');


gr.orderByDesc('opened_at');


gr.query();


while(gr.next()){


gs.print(gr.number);


}


Thanks Anish it worked:)