BizTalk 2009 - Scoped Record Counting in Maps

Posted by StuartBrierley on Geeks with Blogs See other posts from Geeks with Blogs or by StuartBrierley
Published on Fri, 28 May 2010 07:57:24 GMT Indexed on 2010/05/28 9:12 UTC
Read the original article Hit count: 278

Filed under:

Within BizTalk there is a functoid called Record Count that will return the number of instances of a repeated record or repeated element that occur in a message instance. The input to this functoid is the record or element to be counted.

As an example take the following Source schema, where the Source message has a repeated record called Box and each Box has a repeated element called Item:

Scoped Record Counting Source Schema

An instance of this Source schema may look as follows; 2 box records - one with 2 items and one with only 1 item.

Scoped Record Counting Source Message

Our destination schema has a number of elements and a repeated box record.  The top level elements contain totals for the number of boxes and the overall number of items.  Each box record contains a single element representing the number of items in that box.

Scoped Record Counting Destination Schema

Using the Record Count functoid it is easy to map the top level elements, producing the expected totals of 2 boxes and 3 items:

Scoped Record Counting Record Count Map

Scoped Record Counting Record Count Result

We now need to map the total number of items per box, but how will we do this?  We have already seen that the record count functoid returns the total number of instances for the entire message, and unfortunately it does not allow you to specify a scoping parameter.  In order to acheive Scoped Record Counting we will need to make use of a combination of functoids.

Scoped Record Counting Map

As you can see above, by linking to a Logical Existence functoid from the record/element to be counted we can then feed the output into a Value Mapping functoid.  Set the other Value Mapping parameter to "1" and link the output to a Cumulative Sum functoid. Set the other Cumulative Sum functoid parameter to "1" to limit the scope of the Cumulative Sum.

This gives us the expected results of Items per Box of 2 and 1 respectively.

Scoped Record Counting Results

I ran into this issue with a larger schema on a more complex map, but the eventual solution is still the same.  Hopefully this simplified example will act as a good reminder to me and save someone out there a few minutes of brain scratching.

© Geeks with Blogs or respective owner