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 

I suggested to use transform script onBefore and use target.setValue('fieldName', convertedDate);

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

Hi @Ankur Bawiskar. Kindly assist on this.

 

I have tried the same in onbefore transform script as you suggested.

var iso = source.u_XXXX;
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);
target.setValue('field_name', gt);
 
But still in the Target table the date&time field is somehow still copying the Updated date&time of the record.

@Jake Adams 

did you check was your time converted to GMT before setting the value using target object?

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

@Ankur Bawiskar  

 

My bad. Just checked again and seems the transform map is in scoped application hence unable to use Package calls.

 

How can I convert this in scoped application?

@Jake Adams 

this is sample script in scoped app which works

try as per your timezone

var now = new GlideDateTime();
gs.print("System Time is " + now);
var gsdt = new GlideScheduleDateTime(now);
gsdt.setTimeZone("Europe/London");
gs.print("London time is " + gsdt.getGlideDateTime().getDisplayValue());
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader