cancel
Showing results for 
Search instead for 
Did you mean: 

MapWithDefault for empty elements

former_member198060
Participant
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

bhavesh_kantilal
Active Contributor
0 Kudos
  • One alternate to this could be to use FixValues, where you can set  empty value as source and target as "test"
  • And select the copy source value if not found option..

Regards

Bhavesh

vadimklimov
Active Contributor
0 Kudos

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

bhavesh_kantilal
Active Contributor
0 Kudos

This is what I meant,

Answers (1)

Answers (1)

former_member198060
Participant
0 Kudos

Thank you, following the fixValue approach as it is more lightweight than the IF approach (which I've used before as well).

markangelo_dihiansan
Active Contributor
0 Kudos

It could probably be better to use a UDF and place it in a function library just in case you will be re-using the logic in the future.