copying OOB date field to a custom date field

Demo24
Tera Expert

Hello,

I have a requirement to edit system field "sys_created_on" but since they are OOB system fields and best practice is not to edit these, I decided to create a date/time field "u_creation_date" so that this creation date field can be editable by certain role bearing users and this new field can be used for the reporting purpose.

but since at the start the field is empty, I want the value to be copied from OOB "sys_created_on" field and will edit it later if needed. To copy this I tried below fix script in my PDI first:

var gr = new GlideRecord('u_test_table');
gr.query();
while(gr.next())
   {
if(gr.u_creation_date == ''){
   gr.u_creation_date = gr.getValue('sys_created_on');
   gr.setWorkflow(false);
   gr.autoSysFields(false);
   gr.update();
}
}



now, the issues are:

find_real_file.png

1. The field is not copying exact value as that in OOB created field for few records. How do I copy exact value

2. I should run this fix script on production instance where there will be around 50000 records, will that be okay or will there be any data loss if I do it on production. Is this not recommended? if yes then is there any alternate solution for this?

Please help me with this!

1 ACCEPTED SOLUTION

Charles Louis1
Giga Expert

Hi

Can you try this 

var gr = new GlideRecord('u_test_table');

gr.query();

while(gr.next()){

if(gr.u_creation_date == '')

{

var gdt=new GlideDateTime(gr.sys_created_on);

gr.u_creation_date = gdt;

gr.setWorkflow(false);

gr.autoSysFields(false);

gr.update();

}

 

Please Mark it as correct if its helpful.

View solution in original post

8 REPLIES 8

Harish KM
Kilo Patron
Kilo Patron

Hi use this in your script to set date value

gr.setValue('u_creation_date ', gr.getDisplayValue('sys_created_on')); // this should give you exact value test run in back ground script first

Regards
Harish

Hi,

I tried this but same issue occurred.

Anil Lande
Kilo Patron

Hi,

Is this happening for few records only? This is because difference in time zones. Records are created by users who are different time zone and you are  updating these records then it takes value as per your time zone. 

Please try different API's and see if you get expected values.

 

Thanks,
Anil Lande

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi,

yes, this is happening for some records only.

Could you please suggest any different APIs and the script part for this?