Biztalk Mapping Pattern: Iteration Based Value Mapping
Problem Scenario
While discussing a mapper scenario on Microsoft Biztalk Server General form on a thread, the OP asked about a scenario where he wanted to map the data from multiple input messages to the destination based on the iteration of the records, meaning data from Iteration 1 of Message 1 and Iteration 1 of the Message 2 should be clubbed together in the destination. This article discusses the design approach for the issue. The sample requirement is mentioned below.
- Input Message1: Application
<ns0:Application xmlns:ns0="http://iterationbasedvaluemapping.app/">
<Applicant>
<Firstname>Firstname_0</Firstname>
<LastName>LastName_0</LastName>
</Applicant>
<Applicant>
<Firstname>Firstname_1</Firstname>
<LastName>LastName_1</LastName>
</Applicant>
<Applicant>
<Firstname>Firstname_2</Firstname>
<LastName>LastName_2</LastName>
</Applicant>
<LoanInfo>
<LoanAmount>LoanAmount_0</LoanAmount>
</LoanInfo>
</ns0:Application>
- Input Message2: Seg
< ns0:Seg xmlns:ns0="http://iterationbasedvaluemapping.segschema/">
< SegInfo >
< SegName >SegName_0</ SegName >
< SegListName >SegListName_0</ SegListName >
</ SegInfo >
< SegInfo >
< SegName >SegName_1</ SegName >
< SegListName >SegListName_1</ SegListName >
</ SegInfo >
< SegInfo >
< SegName >SegName_2</ SegName >
< SegListName >SegListName_2</ SegListName >
</ SegInfo >
</ ns0:Seg >
- Output Message: ApplicationSeg
<ns0:ApplicationSeg xmlns:ns0="http://iterationbasedvaluemapping.response/">
<Applicant>
<FirstName>FirstName_0</FirstName>
<LastName>LastName_0</LastName>
<SegName>SegName_0</SegName>
<SegListName>SegListName_0</SegListName>
<LoanInfo>LoanInfo_0</LoanInfo>
</Applicant>
<Applicant>
<FirstName>FirstName_1</FirstName>
<LastName>LastName_1</LastName>
<SegName>SegName_1</SegName>
<SegListName>SegListName_1</SegListName>
<LoanInfo>LoanInfo_0</LoanInfo>
</Applicant>
<Applicant>
<FirstName>FirstName_2</FirstName>
<LastName>LastName_2</LastName>
<SegName>SegName_2</SegName>
<SegListName>SegListName_2</SegListName>
<LoanInfo>LoanInfo_0</LoanInfo>
</Applicant>
</ns0:ApplicationSeg>
Design Approach
Since data from multiple input messages is to be mapped to the destination, it becomes imperative to use an orchestration in the scenario, with a multipart message being fed as a source to the mapper and then obtaining the desired output.The xsds for the Input messages and destination message are as follow.
- Application.xsd
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://iterationbasedvaluemapping.app/" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://iterationbasedvaluemapping.app/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Application">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="Applicant">
<xs:complexType>
<xs:sequence>
<xs:element name="Firstname" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LoanInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="LoanAmount" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
- Seg.xsd
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://iterationbasedvaluemapping.segschema/" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://iterationbasedvaluemapping.segschema/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Seg">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="SegInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="SegName" type="xs:string" />
<xs:element name="SegListName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
- ApplicationSeg.xsd
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://iterationbasedvaluemapping.response/" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://iterationbasedvaluemapping.response/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ApplicationSeg">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Applicant">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
<xs:element name="SegName" type="xs:string" />
<xs:element name="SegListName" type="xs:string" />
<xs:element name="LoanInfo" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The design Steps are as follows
In the orchestration create following messages, msgAppReq(for App.xsd), msgSegReq(for Seg.xsd), msgAppResp(for ApplicationSeg.xsd)
Use the construct shape to construct the msgAppResp.
Use the transform Shape for mapping the input messages to the intended output messages. The transform Shape Configuration Should look as below screen shot.
Once Ok is clicked, the mapper will launch. Create the mapping as shown below.
Once the mapping is finished, the Output of the map can be tested.
Conclusion
Using the Iteration functoid, logical functoid and Looping Functoid, the required result can be achieved.
References
The functoids and the logic implemented in the design are referred from MSDN. The readers are advised to go through following links
See Also
Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki