Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 17778

Solved: Nested and conditional parent and child Table Looping Functoid in BizTalk mapping

$
0
0

Introduction

BizTalk mapping tool is a very powerful tool once you get the hang of it. Sometimes you would need to produce some structure in the output schema that did not exist in the source schema, the Table Looping functoid is built for this specific task.

In some other cases you would need to generate a parent child kind of structure. In this blog post I will present the solution to use out of the box functoids to be able to generate this structure.

Problem

Suppose you have the following as the input schema.

clip_image002

And the following output schema.

clip_image004

The requirement is to generate two Message elements in the ProcessRoot output schema. It is also required to generate some fields in the fields array inside each message. These fields are specific for each message and depend on the message ID field. So to be more specific let’s say that we have the following XML input:

<ns0:ProcessRequest xmlns:ns0="http://BTSTest.InputSchema">

 <Parameter>Parameter_0</Parameter>

</ns0:ProcessRequest>

And we want to generate the following XML output from it:

<ProcessRootID="9843748">

  <MessageMessageID="ID1">

    <EntityEntityName="GM">

      <FieldName="code"Value="Val" />

      <FieldName="text"Value="txtval" />

      <FieldName="key"Value="Parameter_0" />

    </Entity>

  </Message>

  <MessageMessageID="ID2">

    <EntityEntityName="GM">

      <FieldName="text"Value="Parameter_0" />

    </Entity>

  </Message>

</ProcessRoot>

As you can see we have two challenges:

1-     You need to create not just an array of two messages for one node in the input message, but also some sub-fields within each message.

2-     The fields generated are dynamic and dependent on the value of one of the fields of parent array.

Solution

Because I want to generate some structure that does not exist in the original message then we have to use the Table Looping and Table Extractor functoids. Now the challenges listed above is the key here on how to develop this. So I had many ways I tried to implement this but mainly they all involved creating two Table looping functoids one for the parent structure and one for the child array. The challenge I had was how to link them and make the second table looping functoid dependent on the first one. Here is the map I ended up implementing:

clip_image006

There are some key points here to consider.

First the first table looping functoid generates the parent array of messages and hence it is linked to the output node of the messages as per this figure:

clip_image008

Also the table of this functoid has the following structure to be generated:

clip_image010

The second notice here is that we have a link from the first column of the parent table looping functoid and the first column also of the child table looping functoid linked to the output fields array to make the generation of the fields conditional if it is equal to the message ID of its parent. This means that second table looping functoid has to include the message ID as part of the table also it will not be generated in the output.

clip_image012

Now ideally this would mean that the table of the child table looping functoid should be as follows:

clip_image014

But when I tried this it never worked (and until now I do not know why) when I debugged the generated XSLT I noticed that the first two rows generated from this functoid are always wrong. When performed further testing I noticed that the child functoid always has bad rows generated out of it that are exactly equal to the number of rows generated from the first table looping functoid. So what I ended up doing is that I added two extra dummy rows that I made sure will never generate anything in the output schema by making sure that the value that would be compared is always not equal. So what I ended up doing is configuring the second table looping functoid as follows.

clip_image016

This achieved exactly what I wanted and produced the required output XML.

The sample input schema, output schema, and the above described map can be found here.

Happy BizTalking J


Viewing all articles
Browse latest Browse all 17778

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>