Using Dynamic Maps in Microsoft BizTalk

Using maps in a Microsoft BizTalk orchestration is pretty straightforward – create your source and destination schemas, map from one to the other, drop a Transform shape onto your orchestration, and configure the source and destination messages. But what if you need to apply different maps based on some property inside the message, or even who the message is coming from?

In our case, we process X12 837 healthcare claim files. In the X12 schemas, the same piece of information can be stored in different locations, and we are unable to enforce a standard, we have to take whatever our clients give us. So, the orchestration has to figure out which map to use to transform the 837 data to our internal schema. We do this using Dynamic Maps.

In this post I’ll demonstrate how to take an input file containing a customer name, and their home and work addresses, and transform using using one of two different maps – one that uses the home address and one that uses work. Yes, this probably isn’t terribly realistic, but it’s fine for a demo!

To begin, create an input schema to represent customer data, like this:

DynamicMapping1

Promote the Map element. This is how we’ll tell the orchestration which map to use. You could also base the decision on a context property (maybe something to do with the party agreement), a part of the filename, etc.

Next, create an output schema like this:

DynamicMapping2

Then create two maps, one using the home address:

DynamicMapping3

…and one using the work address:

DynamicMapping4

Now for the orchestration. Drag a mess of shapes out until you have something that looks like this:

DynamicMapping5

Create two messages, CustomerData and OutputData, using the two schemas created earlier. Create two variables – mapName (System.String) and mapType (System.Type). Now we’ll start configuring all those expression shapes.

In the GetMapName expression, get the name of the map we’re going to use from the Map promoted property:

mapName = CustomerData.Map;

In Rule_1 of the Decide shape, look at mapName:

mapName == “Home”

In the SetMap expression in the left branch, add:

mapType = System.Type.GetType("DynamicMappingBlogPost1.HomeAddressMap, DynamicMappingBlogPost1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcdefghijklmnop");

You’ll have to substitute the namespace and map name you used, and you’ll replace the PublicKeyToken after deploying the solution the first time.

The statement in the SetMap expression in the right branch will be almost identical, except for the name of the other map.

In the Message Assignment shape in the left branch, add the following code to do the transformation:

transform (OutputData) = mapType(CustomerData);

You’ll notice that in the right branch, I used an Expression shape rather than a Message Assignment. You can do this either way, but if you use the Expression shape you have to wrap the transform statement inside a construct statement:

construct OutputData
{
    transform (OutputData) = mapType(CustomerData);
}

Deploy the project, and in the Administration Console, right-click one of the maps and choose Properties. On the Assembly line, copy the PublicKeyToken, and paste it into each of the SetMap expressions where it currently has “abcdefghijklmnop”. Deploy the project one more time.

Configure the send and receive ports, and test using a schema like this:

<ns0:Customer xmlns:ns0="http://DynamicMappingBlogPost1.CustomerData_XML">
  <Name>John Smith</Name>
  <Age>42</Age>
  <HomeAddress>
    <Street>1234 Home Street</Street>
    <City>Plano</City>
    <State>TX</State>
    <Zip>75002</Zip>
  </HomeAddress>
  <WorkAddress>
    <Street>567 Work Ave.</Street>
    <City>Dallas</City>
    <State>TX</State>
    <Zip>75240</Zip>
  </WorkAddress>
  <Map>Work</Map>
</ns0:Customer>

Change the Map node from “Work” to “Home” and verify that a different address is mapped each time.

You can download a complete version of this project at: Dynamic Mapping Example.

Technorati Tags:

oreilly.com - Your tech ebook super store

Print | posted @ Monday, December 30, 2013 8:00 PM

Comments on this entry:

No comments posted yet.

Post A Comment
Title:
Name:
Email:
Comment:
Verification: