I’ve decide to update and repost several BizTalk development tips after getting quite a few email questions on mapping. Please keep those questions coming!

One issue that always comes up when creating output nodes conditionally is how to determine the position or LineNumber of the nodes conditionally created. Normally, this is done by connecting the Iteration functoid (which uses the XSLT position() function to determine which input node is currently being processed) from the inbound looping structure to a field in the outbound schema. This will create a LineNumber value for each conditionally created node such as 1, 4, 7, 10, etc. Unfortunately, what we want is the position() of the output node being conditionally created so that our LineNumber values are in sequence such as 1, 2, 3, 4, etc.

Figure 1. Counting Line Items

Once again, the answer is to turn to the Scripting functoid and write some simple Inline C# code to accomplish this. One thing to note is that Inline scripts are also useful for declaring global variables that can be accessed from any number of scripts in your map. In the map shown above, I used this idea to create a System.Text.StringBuilder object called LineItem that would act as a text counter. Since the LineItem variable is global, it is only updated when the CurrentLine method is called.

Figure 2. Inline C#

This script uses the StringBuilder.Append method to add one character to the LineItem object each time an output node is conditionally created and uses the StringBuilder.Length property to return the LineNumber value in the outbound document.

I used to think that there were more elegant solutions available but after using this for over two years, I’m not so sure. This was a quick and easy way to solve the problem and shows just how flexible mapping can be in BizTalk Server 2006.

Technorati Tags: BizTalk Server, BizTalk

Share this post: Email it! | bookmark it! | digg it! | reddit!| kick it!