- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 03:11 PM - edited 07-16-2024 03:16 PM
Hello Experts, I need to pick the newest approval record [From time stamp] on sysapproval table for a RITM. Please help me out. Thank you in advance.
I get below two Records in the result, and I need to pick the Top one [Newest one].
Please advise how do I sort to get the Newest one.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 03:39 PM
Hi @Sunny14 ,
You can just put the orderByDesc on sys_created_on
Here is the updated script-
var approvalRec = new GlideRecord('sysapproval_approver');
approvalRec.addQuery("sysapproval", "96f9fcb99772bd5458dfbb4e6253af67"); // Sysid of RITM
approvalRec.addQuery("state", "approved");
approvalRec.orderByDesc('sys_created_on'); // Order by created date in descending order
approvalRec.setLimit(1);// this would always return only one record. This is optional if you need it you can use
approvalRec.query();
if (approvalRec.next()) {
gs.info('Newest Record Created on: ' + approvalRec.sys_created_on);
gs.info('Approval Record Sys ID: ' + approvalRec.sys_id);
}
The above script will always sort the data with latest record at the top.
Note- User setLimit() - to limit the number of records for returning so that you get only one record.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 03:39 PM
Hi @Sunny14 ,
You can just put the orderByDesc on sys_created_on
Here is the updated script-
var approvalRec = new GlideRecord('sysapproval_approver');
approvalRec.addQuery("sysapproval", "96f9fcb99772bd5458dfbb4e6253af67"); // Sysid of RITM
approvalRec.addQuery("state", "approved");
approvalRec.orderByDesc('sys_created_on'); // Order by created date in descending order
approvalRec.setLimit(1);// this would always return only one record. This is optional if you need it you can use
approvalRec.query();
if (approvalRec.next()) {
gs.info('Newest Record Created on: ' + approvalRec.sys_created_on);
gs.info('Approval Record Sys ID: ' + approvalRec.sys_id);
}
The above script will always sort the data with latest record at the top.
Note- User setLimit() - to limit the number of records for returning so that you get only one record.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:32 PM
Thank you very much @Community Alums
Awesome. This is exactly I was looking for.
Thanks.
Sunny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:39 PM
Thank you @Community Alums
This resolves my issue.
Thanks.