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

@Sathwik1 

try this

var updatedTime = new GlideDateTime(gr.sys_updated_on);

   gr.setValue('latest_date', updatedTime.getValue());

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

Vishal Birajdar
Giga Sage

Hi @Sathwik1 

 

This might be because when you do 'gr.update()' , 'sys_updated_on' will get updated again with current date and time Or as Ankur suggested may be different timezone issue.

 

If possible ,Can you let us know what you are trying to do here... 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

How to fix timezone issue?