Final Solution: BizTalk mapper: If...Then...Else
Problem
You need to map values from the source to the destination message depending on whether a logical condition evaluates to true or false.
Solution
Define the logical condition that the mapping actions should be based on by dragging logical functoids from the Toolbox onto the map surface. Any functoid or combination of functoids that returns a Boolean value can establish the logical condition, but these functoids can return only true or false.
In this example, the logical condition will check whether the amount of a sale is greater that 1,000, as shown in Figure 1.
Figure 1. Creating the logical operator
Only large sales should appear under the <BigSales> element in the destination message,so the logical condition will check if the Amount in the source message is greater than 1,000.
1. Drag a Greater Than functoid from the Logical Functoids tab of the Toolbox onto the map surface.
2. Select the Amount field of the input message. Drag the cursor over the Greater Than functoid while pressing the mouse button to establish the first comparison value.
3. Right-click the functoid on the map surface and select Properties.
4. In the Properties window, click the Configure Functoid Inputs field, and then select the ellipsis that appears.
5. Define the constant value in the Configure Functoid Inputs dialog box by selecting the second button from the left at the top of the window.
These steps define the logical operation that determines mapping actions, as shown in Figure 2.
Next, define the mapping actions that depend on the evaluation of the logical condition.
In this example, the contents of the <Sales> elements should map to different parts of the destination message, so the map must use the Boolean outcome of the logical comparison as input to a Value Mapping functoid.
1. Drag a Value Mapping functoid from the Advanced Functoids tab of the Toolbox to theright and below the Greater Than functoid.
2. Create a link from the Greater Than functoid to the Value Mapping functoid.
3. Create a link from the Amount field of the input message to the Value Mapping functoid to determine the value mapped when the logical condition is true.
4. Create a link from the Value Mapping functoid to the SaleAmount field appearing under the BigSales record to define where the large value will occur in the destination message.
Figure 2. Defining the comparison value
The Value Mapping functoid defines the action the map should take when the logical condition evaluates to true. Both the amount of the big sale and the name of the sales representative must appear in the destination message in this example, so the map must use two Value Mapping functoids, as shown in Figure 3.
Figure 3. Defining conditional mapping actions
BizTalk must also know that it should create only the <RepSales> element in the destinationmessage when the amount is greater that 1,000. Establishing a link from the logical operator to the RepSales element will ensure that BizTalk creates this parent to the actual values mapped.
When the logical condition evaluates to false, BizTalk should map the sale to the <SmallSales> part of the destination message. The map can check this directly by placing a Not Equal functoid on the mapping surface and comparing to the result of the logical comparison established earlier with a constant value equal to true, as shown in Figure 4.
Figure 4. Defining the else condition
Finally, define the mapping actions that BizTalk should take when the logical comparison is not true. In this example, the Value Mapping functoids simply need to map under the <SmallSales> element in the destination message.
1. Drag a Value Mapping functoid onto the map surface.
2. Create a link from the Not Equal functoid that represents the else case to the Value Mapping functoid.
3. Create a link from the Amount field of the source message to the Value Mapping functoid.
4. Create a link from the Value Mapping functoid to the SaleAmount field appearing underthe SmallSales record to define where the small value will occur in the destination message, as shown in Figure 5.
Figure 5. Completed If . . . Then . . . Else map