BizTalk: Conditional looping incorporating the Greater Than functoid.

This article shows how achieve conditional looping in a BizTalk map using the Looping functoid and the Greater Than functoid. This is useful in a scenario where there multiple repeating nodes in your source schema which you need to map to a single node structure in your destination schema.

This article shows how achieve conditional looping in a BizTalk map using the Looping functoid and the Greater Than functoid.  This is useful in a scenario where there multiple repeating nodes in your source schema which you need to map to a single node structure in your destination schema.

By incorporating the Greater Than functoid you can consolidate the multiple repeats from the source schema into the destination schema based on qualifying criteria. For example this solution consolidates Web, Phone and Postal customer orders into a single document if the order value is over a specific amount.

Pre-requisites
It is assumed you have a working knowledge of BizTalk 2006, maps, schemas and orchestrations. As such some instructions for creating BizTalk artefacts will be shorthand.

What we will build
This is a simple example containing:

Two schemas (source and destination)
One Map
One Orchestration containing:
A Receive port
A Receive shape
A Construct message shape with a Transform inside it
A Send shape
A Send port
One source file
Input and output directories on your file system

Create the source schema
Open Visual Studio and create a blank BizTalk project. Add a schema, call it SrcOrders.xsd and build it so as to resemble the schema in the following screenshot.



Create destination schema

Add a schema, call it CustomerOrders.xsd and build it so as to resemble the schema in the following screenshot



Create the map
Right click on the BizTalk project and add a map artefact calling it ConditionalLoopingMap.btm.

Add schemas to map
Click the ‘Open source schema’ link on the left and navigate to the SrcOrders.xsd file. Next click the ‘Open destination schema’ link on the right and navigate to the CustomerOrders.xsd.

Add functiods to map
We will end up with a map looking like the one below. You will notice that I have added another map surface page and have split the connections between the schemas into Functoid connections and Ordinary connections. This is to make reading the map simpler.

Map Page 1 – Functoid connections


Map Page 2 – Ordinary connections



Functoid page
From the toolbox, expand the Advanced Functoids tab and drag a Looping functoid onto the map surface. From the source schema drag a connector from the WebOrder, PhoneOrder and PostOrder nodes, connecting each to the left hand side of the Looping functoid.



Highlight each link in turn and set the label text in the properties window. This makes the functoid input parameters more easily readable when viewing the Configure Functoid Inputs dialog as in the screenshot below.



From the right side of the Looping functoid drag a connection to the root node of the repeating structure in your destination schema. In this case it is the ‘Customer’ node. This is the structure that will hold the information brought in from the source schema.



Next drag three Greater than functoids onto the map surface from the Logical Functoids toolbox. We will use these to filter out orders less than a specific value. In this scenario Web orders less than 500, Phone orders less than 1000 and Post orders less than 1500 will not be passed across to the destination schema. These are just arbitrary values I made up for the purposes of this example.

From the source schema drag a connection from the WebOrder:OrderValue node to the left hand side of one of the Greater than functoids. Highlight the connection and in the properties window add a value to the Label property as the following screenshot shows.



Repeat this process for the PhoneOrder:ItemPrice and PostOrder:OrdValue nodes making sure each connector goes to a separate Greater Than functoid. You should end up with a map page looking like the screenshot below.

To set the order limit values double click on each Greater Than functoid in turn and add a second parameter in each. For the Web order set the value of the parameter to 500, for the Phone order: 1000 and for the Post order: 1500. Below is an example of the Web Order Configure Functoid Inputs dialog.



Ordinary connector page

Add a new page to the map by right clicking the current page tab at the foot of the map and selecting ‘Add Page’. Name this page ‘Connections’. This page will hold all the straight through connections between the source and destination schemas.

Drag connections from the source schema to the destination schema as outlined in the table below.



You will end up with a map page looking like the Map Page 2 – Ordinary connections above.

Create the testing Orchestration
We will create an orchestration looking like the one below which we will use to test our map.



Add a new orchestration to the project and call it TableLooping.odx. To the orchestration, add the following:

Add a Message called Message_In with the following properties


Add a Message called Message_Out with the following properties



Add a Receive port with the following properties


Add a Receive shape with the following properties


Add a ConstructMessage shape with the following properties


Add a Transform shape inside the Construct shape. Double click on it to open the Transform Configuration dialog. Select ‘Existing map’ and in the dropdown select ‘ConditionalLoopingMap.ConditionalLoop’ . Configure it so the ‘Transform Source’ is the Message_In and the ‘Transform Destination’ is the Message_Out

Add a Send shape with the following properties


Add a Send port with the following properties


Create Input and Output directory on file system
On your file system create an ‘In’ directory and an ‘Out’ directory. These directories are referenced in the Receive and Send ports you just created. To test this map you will drop a test file conforming to the SrcOrders schema into the ‘In’ directory and it will then be transformed by our map and appear in the ‘Out’ directory.

Create an input file
The easiest way to do this is to simply right click on the SrcOrders.xsd file in Visual studio and select ‘Generate Instance’. The output window will indicate where the file has been generated.

Open the file in the text editor of your choice and edit it so as to resemble the file below

<ns0:Orders Item="Really helpful GizMo" xmlns:ns0="http://ConditionalLoopingMap.SrcOrders">
<WebOrder>
<CustomerName>Jessica Window</CustomerName>
<OrderNumber>0236987</OrderNumber>
<OrderValue>750</OrderValue>
<Address>
<Addr1>12 The Sidings</Addr1>
<Addr2>Flestershire</Addr2>
</Address>
</WebOrder>
<PhoneOrder>
<Name>Scrubs Wallspace"></Name>
<ItemNumber>10258963</ItemNumber>
<ItemPrice>20</ItemPrice>
<ShippingAddress>
<AddrLine1>32 Canalside Path</AddrLine1>
<AddrLine2>WolverOak</AddrLine2>
</ShippingAddress>
</PhoneOrder>
<PostOrder>
<Name>Frameling Drax</Name>
<OrdNum>6666666</OrdNum>
<OrdValue>2250</OrdValue>
<Addr>
<Line1>Battlement Lawn</Line1>
<Line2>Woofer Knob</Line2>
</Addr>
</PostOrder>
</ns0:Orders>

When you drop this file into the ‘In’ directory a file will appear in the ‘Out’ directory named <GUID>.xml

If you open this file you will see something like the file below.

<?xml version="1.0" encoding="utf-8"?>
<ns0:CustomerOrders OrderedItem="Really helpful GizMo" xmlns:ns0="http://ConditionalLoopingMap.CustomerOrders">
<Customer Name="Jessica Window" OrderNumber="0236987">
<ShippingAddress>
<Line1>12 The Sidings</Line1>
<Line2>Flestershire</Line2>
</ShippingAddress>
</Customer>
<Customer Name="Frameling Drax" OrderNumber="6666666">
<ShippingAddress>
<Line1>Battlement Lawn</Line1>
<Line2>Woofer Knob</Line2>
</ShippingAddress>
</Customer>
</ns0:CustomerOrders>

As you can see the resultant file has consolidated the differently named incoming orders from SrcOrder.xml into a standardized structure in the destination schema.

This article shows how using the Looping functoid in conjunction with the Greater Than functoid can standardize data formats between schemas.

This simple yet powerful technique takes an inconsistent repeating structure in a source schema is transforms via the map into a consistently named and structured output document.

Happy Programming.

By BiZTech Know   Popularity  (7124 Views)