Search code examples
biztalkbiztalk-2016biztalk-mapper

Need to map a default value when the source field element node is missing


I have a source and destination schema both with a field element node called as Speciality. It is a simple one to one mapping with a scripting functiod in between to remove white spaces from the string before mapping it to destination schema,

The data in the source schema gets populated by a JSON returned by an API and it returns speciality as an array since it may contain multiple values, but sometimes there is no value to be returned. So, the API returns an empty array in JSON, but when that JSON gets converted into XML the speciality node is missing from the XML while I can see it in the JSON with empty array as 'speciality:[]'. Now since the source element is missing from the XML the value does not get mapped to destination schema and the speciality field also goes missing from destination schema.

In the scripting functiod, I have added a condition to check if the speciality is empty and if it is then return a default value, but this does not work since the source element is missing and mapping never takes place.

Now how do I map a default value to destination when the source element itself is missing from the source schema?.

I have tried making the MinOccurs as 1 in destination schema, but it still doesn't work and also I have also set a default value in destination schema for speciality field, but still the element is missing from destination schema.


Solution

  • If you just want the empty node created in the destination, just use the Concatenate functoid, with the first input as the field, and the second a Constant as an empty string.

    If you want to map a value to it if the source is missing, use the Logical Existence Functoid, and either the mapping functoids or a scripting functoid to set the value.

    enter image description here