โ04-14-2021 01:42 PM
I have an incoming file that has a date value of 00:00.00.000 as a value. I am trying to set it to null. Comparing the exit_date ==โ00:00:00.000โ fails. Checking Date.parse($exit_date)==โ โ or Date.parse($exit_date==null fails. Date.parse($exit_date).ToLocalDateString() fails. Not sure how I can parse this data. Any ideas on how to map this value to null?
Solved! Go to Solution.
โ04-14-2021 05:45 PM
Try this expression in your mapper:
isNaN(Date.parse($.get('exit_date') || '')) ? null : Date.parse($exit_date).toLocaleDateTimeString()
Having not seen your entire input set, I canโt guarantee it will work for every record, but I think it will come very close, if not fully succeed.
The idea of this expression is:
If $exit_date exists and is translatable to dateobject, it will produce a datetime in which the LocaleDateTimeString() will result into a valid value; otherwise the result is null.
It is dependent on the expectation that NaN
is always the result from Date.parse() for non-parsable parameters.
โ04-14-2021 02:12 PM
The conditional operator (? : ) may help here. Is date field a string? If so, something
like this may work. You could replace โ==โ comparison with a string operation (.contains, .startsWith)
MAPPER
Expression : $exit_date == '00:00.00.000' ? null : $exit_date
Target Path : $exit_date
โ04-14-2021 03:04 PM
One thing I notice is that it seems there is a typo in the time-format for either the $exit_date value or the string-comparison expression.
I think "00:00.00.000"
should be "00:00:00.000"
.
(i.e. the minute:second delimiter a colon instead of period)
Also, Date.Parse() should be Date.parse() (lowercase โpโ)
In any case, if the $exit_date value contains the time-format typo, then Date.parse() probably returns a NaN
value instead of null
or ''
(but I havenโt tested to confirm).
โ04-14-2021 04:49 PM
Sorry, Yes I had typos in my question: Hereโs some more detail:
I have a Mapper Snap with this logic:
$exit_date!=โ โ && $exit_date!=null && $exit_date!=โ00:00:00.000โ?
Date.parse($exit_date).toLocaleDateString() : null
I am getting this error message on that snap:
Expression worked for 1 previous document, but failed on document #2 with the error: Not-a-number
(NaN) does not have a method named: toLocaleDateString, found in: โฆaleDateString(). Perhaps you meant: toString, toExponential, toPrecision, toFixed
Resolution:
Handle the NaN value by providing a default value, for example: ($exit_date!=โโ&&$exit_date!=null&&$exit_date!=โ00:00:00.000โ)?(Date.parse($exit_date) || /* default */).toLocaleDateString():null
Reason:
โtoLocaleDateStringโ was not found while evaluating the sub-expression โDate.parse($exit_date).toLocaleDateString()โ
I tried the resolution and the same error appears
โ04-14-2021 05:45 PM
Try this expression in your mapper:
isNaN(Date.parse($.get('exit_date') || '')) ? null : Date.parse($exit_date).toLocaleDateTimeString()
Having not seen your entire input set, I canโt guarantee it will work for every record, but I think it will come very close, if not fully succeed.
The idea of this expression is:
If $exit_date exists and is translatable to dateobject, it will produce a datetime in which the LocaleDateTimeString() will result into a valid value; otherwise the result is null.
It is dependent on the expectation that NaN
is always the result from Date.parse() for non-parsable parameters.