Mapping Unrelated Records

Introduction

I was recently asked to create a map to combine parent records with children records. The challenge was that the children records in the source document where not grouped with their parent record.

Mapping Unrelated Records

The message was similar to the following Xml where StatusItem is related by its ordinal position to DetailStatus/DetailItem. Look carefully at the message; the StatusItem parent node is SummaryStatus, which is at the same level in the Xml as DetailStatus. There is only one SummaryStatus node, and there are multiple DetailStatus nodes – all at the same level in the Xml.

<root>
  <
SummaryStatus>
    <
SummaryCode>102</SummaryCode>

    <
StatusItem>
      <
statusCode>item_0</statusCode>
    </
StatusItem>

    <
StatusItem>
      <
statusCode>item_1</statusCode>
    </
StatusItem>

    <
StatusItem>
      <
statusCode>item_2</statusCode>
    </
StatusItem>
  </
SummaryStatus>

  <
DetailStatus>
    <
DetailItem>
      <
statusCode>detail_0</statusCode>
    </
DetailItem>
  </
DetailStatus>

  <
DetailStatus/>
    <
DetailItem>
      <
statusCode>detail_1</statusCode>
    </
DetailItem>
  </
DetailStatus>

  <
DetailStatus/>
<
root>

In reality a message similar to the above is being provided by an outside source and we cannot modify it. By convention we are given the assumption that there is a DetailStatus record for each StatusItem, however there is not always a DetailItem. Our job is to map the output and combine the StatusItem code with its each DetailItem code.

The output goal is similar to the following Xml:

<root>
  <
SummaryCode>102</SummaryCode>

  <
StatusItem>
    <
StatusCode>item_0</StatusCode>
    <
DetailItem>
      <
StatusCode>detail_0</StatusCode>
    </
DetailItem>
  </
StatusItem>

  <
StatusItem>
    <
StatusCode>item_1</StatusCode>
    <
DetailItem>
      <
StatusCode>detail_1</StatusCode>
    </
DetailItem>
  </
StatusItem>

  <
StatusItem>
    <
StatusCode>item_2</StatusCode
  </StatusItem>
</
root>

The BizTalk map below works by using the Iteration Functoid comparing the position of the current SummaryStatus parent record to the position of the DetailStatus record. Additionally the Logical Existence Functoid is used so that if a DetailItem does not appear in the source message, then it won’t appear in the Target message.

MapParentToChild

External Links from MSDN

Previous Articles