- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2024 05:02 PM
If there are multiple "gr.dates" of the written script, I would like to return the one with the latest 'sys_updated_on' of "gr.date".
Please tell me how to extract it.
var gr = new GlideRecord('test_table');
gr.addQuery('test,'00');
gr.query();
while (gr.next()) {
return gr.date;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 12:57 AM
Hi @user_ms
Try this script -
var gr = new GlideRecord('test_table');
gr.addQuery('test', '00');
gr.orderByDesc('sys_updated_on'); // Order the results by sys_updated_on in descending order
gr.query();
if (gr.next()) {
return gr.date; // If there's at least one record found
} else {
return null; // Handle case where no records were found
}
Please Mark this Helpful and Accepted Solution, if this helps to resolve your query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 05:11 AM
Hi,
Here is the updated code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 05:18 AM - edited 04-22-2024 05:24 AM
Hello,
Use orderByDesc attribute to get the latest one.
var gr = new GlideRecord('test_table');
gr.addQuery('test,'00');
gr.orderByDesc('sys_updated_on');
gr.query();
if(gr.next()) {
return gr.date;
}
Abdul Fathah
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 12:57 AM
Hi @user_ms
Try this script -
var gr = new GlideRecord('test_table');
gr.addQuery('test', '00');
gr.orderByDesc('sys_updated_on'); // Order the results by sys_updated_on in descending order
gr.query();
if (gr.next()) {
return gr.date; // If there's at least one record found
} else {
return null; // Handle case where no records were found
}
Please Mark this Helpful and Accepted Solution, if this helps to resolve your query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 05:11 AM
Hi,
Here is the updated code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 05:18 AM - edited 04-22-2024 05:24 AM
Hello,
Use orderByDesc attribute to get the latest one.
var gr = new GlideRecord('test_table');
gr.addQuery('test,'00');
gr.orderByDesc('sys_updated_on');
gr.query();
if(gr.next()) {
return gr.date;
}
Abdul Fathah
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.