- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 12:55 AM
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;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:04 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:04 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 07:19 AM
hi sir it is not working properly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:07 AM
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