Script to copy dates from one field to another

danenglish
Giga Expert

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!  

1 ACCEPTED SOLUTION

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();



}


View solution in original post

6 REPLIES 6

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi,



You can develop fix script which will copy dates for current record.


You can reuse same script from your business rule in fix script.



You just need to replace current object to table glideojbect in fix script.



Regards,


Sachin


Thanks for the reply, Sachin.   I'm a low-coder, perhaps you could help me out because my business rule is very simple.



(function executeRule(current, previous /*null when async*/) {




  current.due_date = current.start_date;




})(current, previous);



How would I translate this to a fix script?


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();



}


This worked like a charm, I placed it into a scheduled weekly job and ran it initially and it populated the field in all records... now it'll just catch those that are missing the Start date going forward.