Geeks With Blogs

Bill Osuch - Random geek notes

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:


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:


Then create two maps, one using the home address:


…and one using the work address:


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


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=, 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>
    <Street>1234 Home Street</Street>
    <Street>567 Work Ave.</Street>

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: - Your tech ebook super store

Posted on Monday, December 30, 2013 8:00 PM BizTalk , Mapping | Back to top

Comments on this post: Using Dynamic Maps in Microsoft BizTalk

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Bill Osuch | Powered by: