how to fetch the recent record from table

Debarpita
Tera Contributor

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);

}

2 REPLIES 2

Paul Curwen
Giga Sage

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

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

tried that it is fetching the previous created record Xyz company name