- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 02:16 PM
Hi all. I'm frustrated after a couple of hours of trying to do something that I would normally consider simple.
I need a script to copy all of the dates from one field in the planned_task table to another. There is a field called start_date that is full of data (and only on the planned_task table) that I want to copy to the field called due_date (which is extended from the task table), because the previous administrator of the system created the start_date field to replace due_date for some reason, but I want to use due_date so it rolls up to the task table.
I am fine on the business rule side with updating this information as records are created/updated, but I need a script to go through the current records and copy all of this data to the proper field.
All help is always greatly appreciated!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 03:31 PM
Hi Dan,
You can copy below in your fix script and run fix script.
var ptask = new GlideRecord('planned_task');
ptask.addEncodedQuery('numberISNOTEMPTY');
ptask.query();
while(ptask.next()){
ptask.due_date = ptask.start_date;
ptask.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017 02:58 PM
Hello Dan,
You can create a fix script or execute one-time script via background script to copy the field for existing records.
Sample script:
var gr = new GlideRecord('incident');
gr.addQuery("active=true^sys_created_on<javascript:gs.daysAgoStart(0)");
gr.query();
while(gr.next())
{
gr.setValue('short_description', gr.u_test);
gr.setWorkflow(false);
gr.update();
}
Reference:
http://wiki.servicenow.com/index.php?title=GlideRecord#gsc.tab=0
Background Scripts — ServiceNow Elite
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 08:15 AM
Thanks all, I'll give these a try in my dev environment today and see how it goes!