on 06-29-2016 9:05 AM
Hello all,
I have a question regarding mapWithDefault function:
If I have an empty source field, the mapWithDefault does not seem to work. It only works if the source field is not existing. E.g:
Mapping:
source field a -> mapWithDefault('Test') -> target field a
Test for empty field:
Source:
<a></a>
Result:
<a></a>
Test with removed field:
Source:
Result:
<a>Test</a>
What I would like is to have the mapWithDefault value also for empty fields (so the first example above should also create <a>Test</a> as the output). What is the best way to achieve this? I know it works with an IF condition which checks for the empty value specifically, but maybe there is a better option?
Regards
Bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
MapWithDefault checks if the element exists in the context or not - if it exists, but with no value (empty), MapWithDefault will use empty value, as you observed. That is not a bug, this is the expected behaviour of MapWithDefault function.
As an alternative to the solution provided by Bhavesh, you can use IF function and check against empty value in the source field if that field exists in the context:
Regards,
Vadim
Thank you, following the fixValue approach as it is more lightweight than the IF approach (which I've used before as well).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.