
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 12:34 AM
How to update the created date ,by past 2 days ago from current date on incident .
For example if incident0123 created 23-03-2021 - 2 days =incident0123 created 21-03-2021
How to achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 01:53 AM
you can use this script to set the Created Date/Time 2 days from it's current Created Date/Time
var inc = new GlideRecord('incident');
inc.addQuery('number', 'INC001');
inc.query();
if(inc.next()){
var gdt = new GlideDateTime(inc.sys_created_on);
gdt.addDaysUTC(-2);
inc.sys_created_on = gdt;
inc.autoSysFields(false);
inc.setWorkflow(false);
inc.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 01:39 AM
Hello
Please try this script in background script and let me know if it worked.
var dt = "23-03-2021";
var gdt = new GlideDate();
gdt.setDisplayValue(dt);
gdt.addDays(-2);
gs.print(gdt.getValue());
Regards,
Omkar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 01:42 AM
Create a before business rule on insert of the record and use the below code:
var gdt = new GlideDate();
gdt.addDays(-2);
gs.print(gdt.getValue());
current.sys_created_on = gdt.getDisplayValue();
current.autoSysFields(false);
For updating System fields, you have use current.autoSysFields(false) to not get updated by system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 01:53 AM
you can use this script to set the Created Date/Time 2 days from it's current Created Date/Time
var inc = new GlideRecord('incident');
inc.addQuery('number', 'INC001');
inc.query();
if(inc.next()){
var gdt = new GlideDateTime(inc.sys_created_on);
gdt.addDaysUTC(-2);
inc.sys_created_on = gdt;
inc.autoSysFields(false);
inc.setWorkflow(false);
inc.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2021 03:36 AM
It's not updating for particular user .