Date format transform maps

Khanna Ji
Tera Guru

Hi All,

I am getting date in file as this format 20200831 Year, month and date format. Now I have a target field on the target table which accepts date in the format 01/12/2020 00:00:00 (Date,month, year and time).

I tried below code but its not working in transform map

var startDate = source.u_date;
var year = startDate.substr(0, 4);
var month = startDate.substr(4, 2);
var day = startDate.substr(6, 2);
var finalDate = day + '/' + month + '/' + year + ' 00:00:00';
var gdt = new GlideDateTime(finalDate);
return gdt;

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

1) don't use field map for this

2) Handle this by using Transform map onBefore script

3) don't give time part; it will be auto handled by GlideDateTime()

I have removed -> + ' 00:00:00'

Also displaying it with / or - is as per the user's date/time format but the below part will set value correctly in internal

Updated final script:

var startDate = source.u_date;
var year = startDate.substr(0, 4);
var month = startDate.substr(4, 2);
var day = startDate.substr(6, 2);
var finalDate = day + '/' + month + '/' + year ;
var gdt = new GlideDateTime(finalDate);
target.<fieldName> = gdt; // give here the target field name here

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

1) don't use field map for this

2) Handle this by using Transform map onBefore script

3) don't give time part; it will be auto handled by GlideDateTime()

I have removed -> + ' 00:00:00'

Also displaying it with / or - is as per the user's date/time format but the below part will set value correctly in internal

Updated final script:

var startDate = source.u_date;
var year = startDate.substr(0, 4);
var month = startDate.substr(4, 2);
var day = startDate.substr(6, 2);
var finalDate = day + '/' + month + '/' + year ;
var gdt = new GlideDateTime(finalDate);
target.<fieldName> = gdt; // give here the target field name here

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

hi sir it is not working properly

Jaspal Singh
Mega Patron
Mega Patron

Can you replace

var finalDate = day + '/' + month + '/' + year + ' 00:00:00';
var gdt = new GlideDateTime(finalDate);
return gdt;

with

var finalDate = day + '/' + month + '/' + year + ' 00:00:00';
//var gdt = new GlideDateTime(finalDate);
return finalDate;

Also, ensure the field date time format you specify for the map if its a transform map script

find_real_file.png