Tuesday, September 6, 2011

BizTalk conditional mapping of repeatable records

Was a question in one of the msdn forums, that when mapping repeatable record elements based on a condition to elements of the same record in the destination schema after using the looping functoid, the loop runs only once. In the example in Fig. 1, in the source schema Root1, PHRoot, Record1 and Record2 are all unbounded and in the destination schema RecordDest is also unbounded. Based on element Root1Ele's and Field1's value we need to map Field3 to either FieldGW or FieldLen in the destination. Instinctively we would try to use the looping functoid in such scenarios, but in fact it is not required.

Fig 1. BizTalk conditional mapping scenario
The following was the test sample source and test result.

Source:
<ns0:Root1 xmlns:ns0="http://LoopFunctoid.Schema1">
 <Root1Ele>Root1Ele_0</Root1Ele>
 <PHRoot>
 <FieldRoot>PH</FieldRoot> 
 <Record1>
 <Field1>GW</Field1> 
 <Field2>Field2_0</Field2> 
 </Record1>
 <Record2>
 <Field3>101</Field3> 
 <Field4>Field4_0</Field4> 
 </Record2>
 </PHRoot>
<PHRoot>
 <FieldRoot>PH</FieldRoot> 
 <Record1>
 <Field1>LEN</Field1> 
 <Field2>Field2_0</Field2> 
 </Record1>
 <Record2>
 <Field3>202</Field3> 
 <Field4>Field4_0</Field4> 
 </Record2>
 </PHRoot>
 </ns0:Root1>

Test Result:
<ns0:Root2 xmlns:ns0="http://LoopFunctoid.Schema2">
 <RecordDest>
 <FieldGW>101</FieldGW> 
 <FieldEle>Root1Ele_0</FieldEle> 
 </RecordDest>
 <RecordDest>
 <FieldLen>202</FieldLen> 
 <FieldEle>Root1Ele_0</FieldEle> 
 </RecordDest>
 </ns0:Root2>

No comments:

Post a Comment