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 03:25 AM
you are using autoSysFields() so it's not updating system field
try 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;
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);
}
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 04:58 AM
Hello @Ankur Bawiskar, I tried your given logic but still ist not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 05:11 AM
so what value is shown in sys_updated_on once your script runs?
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 05:47 AM
@Ankur Bawiskar it's showing me the current t date with the current updation time.
