Fix Script to copy date from a Datetime field to a Date field for all records in the table.

prabhmeet2
Kilo Contributor

Hi,

This is a scenario of my request.

Incident table has a field Opened - which is date time field. I have to create a new field on Incident table my_Opened and its should be date field and I have to create a fix script to copy only the date values for all records from "opened" to "my_Opened" field.

 

1. To create a new column, I did through configure dictionary, is that correct?

2. I have written the below fix script but the dates are increasing by 1- 

var gr = new GlideRecord('incident');

gr.query();
while(gr.next()){

gr.u_my_opened = gr.opened_at;
gr.setWorkflow(false);
gr.update();

The dates in my_opened are increasing by 1, screenshot attached.

Can someone please help.

find_real_file.png

 

1 ACCEPTED SOLUTION

Can you try

 

gr.setValue('u_my_opened', gr.getDisplayValue('opened_at'));

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

10 REPLIES 10

hi,

I tried this but still there is difference in dates.

can you try

gr.setValue('u_my_opened', gr.getValue('opened_at'));

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Hi,

Still the difference of 1 day is coming for some of the dates. Is it due to time zones?

Can you try

 

gr.setValue('u_my_opened', gr.getDisplayValue('opened_at'));

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

yes thanks i too figured it out , it worked by using getDisplayValue()