« The unanswered questions | Main | True names »

January 19, 2007

Mapping fixed elements into a repeating structure in BizTalk

Suppose that you have to map a source schema containing a set of specialised elements to a destination schema which represents the same data as a repeating structure with a typecode.

For example, consider a source schema that's specific to restaurants, which has specialised Chef and MaitreD elements:

And a destination schema designed for generic payroll, which has a repeating Employee element with a JobTitle:

We want the Chef and MaitreD elements to map to Employee elements, each with the appropriate JobTitle.  We'll also throw FavouriteCuisine and Snootiness into the Comments element.

The trick to this is to use a Table Looping functoid to build a table that corresponds to the Employee structure out of the heterogenous elements and job title constants, then use Table Extractor functoids to pull out the tabular content column by column.

Place the Table Looping functoid.

Drag a link from a "scoping node" in the source.  This just has to be a node at the "right" level.  In our example, the Chef node will do.

Then go into the Configure Functoid Inputs dialog and add an input with the number of columns you need in the table.  In this case, the number of columns is just the number of fields under Employee, namely 4.

These two inputs, the scoping node and the column count, must be the first two inputs.

The order of the other inputs doesn't matter -- just drag links from all the fields that you want to be able to assemble into the table, plus any record nodes that contain these fields (in our case, the MaitreD node).  Give these links labels -- for example label the link from the Chef/Name node ChefName -- we'll see why later.

Finally, we're going to need to use some constant strings in the table for job titles.  These have to be entered as inputs to the Table Looping functoid as well, via the Configure Functoid Inputs box.

Now we can drop in the Table Extractor functoids that will pull data out of the table.  In each case, the inputs are a link from the Table Looping functoid, and the 1-based column number that you're going to use in the table for the destination element, and the output is a link to the destination node.  For example, if you're going to collect names in column 1 and titles in column 2, then the Table Extractor functoid that links to Name has to have 1 as its second input, and the one that links to JobTitle has to have 2 as its second input.  Again you have to enter these via Configure Functoid Inputs.

You also have to drag directly from the Table Looping functoid to the repeating record element.  This tells BizTalk to actually generate instances of the repeater.

When you've done this, your map looks something like this:

And your Table Looping functoid configuration looks something like this:

(Note the number of columns as the second input, and the presence of the job title constants.)

And your Table Extractor functoid configurations look something like this:

 The final step is to tell the Table Looping functoid how to populate its rows and columns.

Open the Table Looping Configuration dialog (in the Table Looping Grid row of the Properties box).  You'll see it's set up with four columns, corresponding to the size you specified in Configure Functoid Inputs.  Because of the way we've set up our Table Extractors, we need column 1 to contain names, column 2 to contain titles, column 3 to contain salaries and column 4 to contain comments.

The key to this dialog is creating multiple rows in this dialog for the different kinds of input that we want to homogenise.

Thus, in row 1, we'll map inputs to columns as appropriate for a Chef, and in row 2, we'll map inputs to columns as appropriate for a MaitreD.  We can choose both link and constant inputs, mixing them as required.  In our example, column 1 is always going to be a link input from whatever/Name, but column 2 is always going to be one of the constant inputs.

In our case, the Table Looping Configuration ends up something like this:

This, by the way, is why labelling the links is important.  The dialog is not resizable and the drop-down box can get quite narrow.  If you don't label the links, they appear as long XPath expressions and it's a pain to figure out which one you want.

January 19, 2007 in Software | Permalink

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c5c9b53ef00d83571ecae69e2

Listed below are links to weblogs that reference Mapping fixed elements into a repeating structure in BizTalk:

Comments

Hi,

I found this article very helpfull, many kudo's 2 U!!!

I have one issue I can't seem to solve regarding this.

I have a similar situation as you describe in this article, only in my xml input message, the
there are two nodes of "Chef" and one node of the MaitreD. after testing the map I see that table looping shows 4 nodes of Employee. 2 Employees of the type Chef and 2 of the type MaitreD, only the second MaitreD is the same and the first one, and it should not be there at all. How could I fix this?

Regards,

Adeel

Posted by: Adeel at Jul 25, 2009 12:19:47 AM

Thank you for this post, I was looking for exactly this.

But why is this so difficult in BizTalk?
In Mapforce, just "duplicate" the target "Employee" node creating a 'virtual' "Employee (2)", and you map Chef's Name, Salary etc to the first, and MaitreD's Name, Salary etc to the second node. Out comes one Payroll node with two Employee child nodes..

Posted by: JW at May 10, 2011 2:14:42 AM