CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeff Lynch [MVP]

Everything E-Commerce!

BizTalk Server 2006: Conditional Output Node Magic!

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: ,


Published Aug 11 2006, 07:44 AM by jlynch
Filed under:

Comments

TrackBack said:

# August 13, 2006 5:54 PM

Leonid Ganeline said:

I've tried using the plain int Counter. It works fine. It's kinda redundant work with this text counter.

Thanks for your very useful articles! Very-very!

# October 17, 2006 3:52 PM

Ashwani said:

Awesome trick!! was facing same kind of issue in my mappings. A great help.

# May 2, 2007 3:57 PM

jlynch said:

Glad you found it useful.

Jeff

# May 2, 2007 4:14 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication