Not able to update sys_updated_on filed using background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 03:19 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 06:14 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 10:24 AM - edited ‎09-20-2023 10:25 AM
Hello @Ankur Bawiskar, now it's giving a blank value for the sys_updated_on field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 08:38 PM
strange
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
