- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2021 12:20 PM
How to convert string field value to date field using transform map
string field value : 01-APR-1967 (u_actual_date)-->string field
date field format : MM-dd-yyyy (actual_start)--> date field
below code not working:
OnBefore
if (!source.u_actual_date.nil()) {
var sec = Date.parse(source.u_actual_date);
var gdt = new GlideDateTime();
gdt.setNumericValue(sec);
target.actual_start = gdt.getDisplayValue();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2021 08:08 AM
I have found the solution by modifying the transform map script
On before
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gd = new GlideDate();
gd.setDisplayValue(source.u_actual_date, "dd-MMM-yyyy");
var dt = gd.getByFormat("MM-dd-yyyy");
target.actual_date= dt;
//gs.info("SUCCESSFUL : ", dt);
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2021 12:24 PM
Hi,
Once you use the field mapping section and add a new entry here, I believe the transform map will ask you to specify the date format for the field in the import table so that it can map it correct to the target date field you've chosen. It's assumed it would most likely be in string anyway, but it'll ask you for the format like:
dd-MMM-yyyy
and then it'll automatically convert it now that it knows how your imported date format is and appropriately match it to the format set within your instance for the target.
No onBefore script should be needed...have you tried to address this from a field mapping perspective?
Example:
So you've pick the correct source field, but the date format field pops up here on the left when you select a target field on the right that is a date field.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 02:29 AM
Hi Allen,
I have tried the mapping too in the transform map, you have stated above. Unfortunately not working.
Below Error:
Unable to format 31-JUL-2017 using format string MM-dd-yyyy hh:mm:ss for the field actual_start

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 05:51 AM
Hi,
Does your source field really have hh:mm:ss?
Please see my exact screenshot for assistance. I tried to help by giving a pretty good example for you to reference.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2021 08:08 AM
I have found the solution by modifying the transform map script
On before
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gd = new GlideDate();
gd.setDisplayValue(source.u_actual_date, "dd-MMM-yyyy");
var dt = gd.getByFormat("MM-dd-yyyy");
target.actual_date= dt;
//gs.info("SUCCESSFUL : ", dt);
})(source, map, log, target);