Not able to update sys_updated_on filed using background script

Mark Wood
Tera Contributor

Hello experts,

I have written the script below to update the sys_updated_on field value using the script. In my background script, it shows me that the record has been updated, but when I check it, it still shows the same date. I want to set it to yesterday's date.

Please guide me on this. Thank you.

 

 


var gdt=new GlideDateTime().getDisplayValue();

gdt.addDaysUTC(-2);
var gr=new GlideRecord('u_ma_frm_event');
gr.addQuery('sys_id','1809434b1b553550a72cfdd2cd4bcb76');
gr.query();
if(gr.next())
{

gr.sys_updated_on=gdt;
gr.update();
gr.setWorkflow(false);
gr.autoSysFields(false);
gs.log(gdt);
gs.log(gr.u_ma_fld_number);

}

7 REPLIES 7

@Mark Wood 

use this

var gdt=new GlideDateTime().getDisplayValue();

gdt.addDaysUTC(-2);
var gr=new GlideRecord('u_ma_frm_event');
gr.addQuery('sys_id','1809434b1b553550a72cfdd2cd4bcb76');
gr.query();
if(gr.next())
{

gr.sys_updated_on = gdt.getValue();
gr.autoSysFields(false);
gr.setWorkflow(false); // this line should be before update to avoid any BR from getting triggered
gr.update();
gs.log(gdt);
gs.log(gr.u_ma_fld_number);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello @Ankur Bawiskar, now it's giving a blank value for the sys_updated_on field.

@Mark Wood 

strange

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader