I want to copy and paste "updated on" value to "latest" value

Sathwik1
Tera Expert

I want to copy and paste "updated on" value to "latest" value by using the below script, Date is updating fine, but time is not updating correctly. what is the issue here?

var gr = new GlideRecord('incident');
gr.addQuery('sys_id','7b8ead8a9363d6105b0f336efaba104b');
gr.query();
if(gr.next())
	{
		gr.latest_date = new GlideDateTime(gr.sys_updated_on);
		gr.update();
	}

 @Ankur Bawiskar 

1 ACCEPTED SOLUTION

@Sathwik1 

that's what I said, set the value in GMT in the new field

did you use this line? and then see in XML if both the values are same

    gr.setValue('latest_date', new GlideDateTime(gr.sys_updated_on));

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Sathwik1 

this line will set the value in GMT. you can verify by checking show XML of the record

the value shown on form or list is as per your timezone

var gr = new GlideRecord('incident');
gr.addQuery('sys_id', '7b8ead8a9363d6105b0f336efaba104b');
gr.query();
if (gr.next()) {
    gr.setValue('latest_date', new GlideDateTime(gr.sys_updated_on));
    gr.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

How to fix this issue? I need same time too..

Expected 2024-07-17 08:15:55

What was updated (based on the above script) : 2024-07-17 13:45:55

Those records might be created by different persons in different timezones.. but now here, I need exact time too.. anything can you suggest? @Ankur Bawiskar 

 

@Sathwik1 

that's what I said, set the value in GMT in the new field

did you use this line? and then see in XML if both the values are same

    gr.setValue('latest_date', new GlideDateTime(gr.sys_updated_on));

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Yes, I used the below line..

   gr.setValue('latest_date', new GlideDateTime(gr.sys_updated_on));
the details above I provided are from XML only..
***** set the value in GMT in the new field -> Means what? I didn't understood this point