how to fetch the recent record from table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 05:29 AM
Hi All,
I want to fetch the current record which is newly created means Abc but in logs i am getting Xyz. Kindly help me.
Script in email script :
var compname = new GlideAggregate('u_teststar');
compname.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^sys_import_set.sys_created_onRELATIVEGT@minute@ago@240');
compname.addAggregate('COUNT(DISTINCT', 'sys_id');
compname.groupBy('u_company');
compname.orderByDesc('sys_created_on');
compname.setLimit(1);
compname.query();
if (compname.next()) {
// companyname = compname.getValue("u_company");
companyname = compname.u_company.getDisplayValue();
gs.log("testyup-companyname-"+companyname);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 05:46 AM - edited 02-01-2023 05:46 AM
Do not use GlideAggregate that is providing a average, sum, (count in your example), just use plain of GlideRecord and orderByDesc on the field sys_created_on
e.g.:
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);
}
If helpful please mark as Helpful/Correct
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 05:49 AM
tried that it is fetching the previous created record Xyz company name