There
can be cases in mapping development when the developer needs to map some fields
conditionally. More exactly, let say that there is need to map in the following
situation: if a source field has a value, then a second source field must be
mapped to a destination field, else, a third source field must be mapped to the
destination field:
IF(SourceField1
== Value1) THEN
DestinationField1 = SourceField2
ELSE
[IF(SourceField1 == Value2)]
DestinationField1 = SourceField3
There
are several solution to do this mapping (for example, using a Script functiod).
In this example, we will do that using ValueMapping functoid.
Let’s
consider the following example: we have a Biztalk application which simply receive
a flat file, disassemble it according to a receive schema, perform a mapping as
described above, assemble it according to a send schema and output the
resulting file to a send port.
The
input file is:
Receive
schema is:
Tag
field if the first character from record (in our example, A or B), Data1 is testdata1_1..5
and Data2 is testdata2_1..5
Send
schema is:
And
map is:
(of
course, is a very simplified map and schemas).
The
logic of the mapping is:
IF(Tag
== “A”) THEN
Dest.Data1 = Source.Data1
ELSE
IF(SourceField2 == “B”)
Data2 = Source.Data2
In Equal functoids, we have 2
comparisons which return true or false:
and
The ValueMapping
functoids functions as follows: if the first parameter is true, then second
parameter value is returned and is mapped to destination fields. Else, no value
is returned, and destination field does not receive anything.
Thus, in
our example, for the fields which starts with “A”, Data1 value will be mapped (testdata1_1..5),
else, Data2 field will be mapped(testdata2_1..5).
According
to these, we obtain output file:
We
can see that, for records 1, 2, and 4 from source file, that start with “A” (Atestdata1_1testdata2_1,
AtestData1_2testdata2_2, Atestdata1_4testdata2_4) we have Data1 fields in
destination file (testdata1_1, testdata1_2, testdata1_4) and for records 3 and
5, that start with “B” (Btestdata1_3testdata2_3, Btestdata1_5testdata2_5), we
have Data2 in destination file (testdata2_3, testdata2_5)
ValueMapping.rar (14.41 kb)