Transform Maps Date/Time updating wrongly

Jake Adams
Tera Contributor

Hi, 

 

The Target Date/Time is updating by adding extra 2 or 3 hours

 

For e.g:) My Source field string field value is 2024-05-09 11:29:47.0

 

Using the source script in the field mapping I am removing the .0

 

answer = (function transformEntry(source) {
var date= source.field_name;
var arrSplit = date.split(".");
var finalString = arrSplit[0].toString(); 
return finalString ();
 
})(source);

 

But the target date/time field is updated as 09/05/2024 15:07:19

 

Kindly assist.

15 REPLIES 15

@Jake Adams 

so do this

1) convert the time from australian time to GMT and then use set value

2) please check which timezone it is since Australia has 5 timezones

refer my blog to convert the timezone and then use that in onBefore transform script don't use field map script

Convert timezone 

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

Hi,

 

Just checked both the Source date and Instance is also in the Australian time zone which means the Target field should also hold the Australian time zone but still as I mentioned when the source updates to the target its updating it wrongly.

Hi @Ankur Bawiskar 

 

Looking further into this, it seems that it is treating the Source date&time as being from UTC time and while it's transformed to Target date&time field it's always adding extra 10hrs or 2hrs or 3hrs.

 

How to fix this?

 

 

@Jake Adams 

while setting value it will set in UTC

Convert the incoming value to GMT and then set and it will work fine

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

Hi @Ankur Bawiskar,

 

I tried it using the below:

 

answer = (function transformEntry(source) {

    var iso = source.*****;
    var gt = new GlideDateTime(iso);

    var tz = Packages.java.util.TimeZone.getTimeZone("GMT");
    gt.setTZ(tz);
    var timeZoneOffSet = gt.getTZOffset();
    gt.setNumericValue(gt.getNumericValue() + timeZoneOffSet);
    return gt;
})(source);
 
But in the Target table the date&time field is copying the Updated date&time of that record.