BizTalk: Incorporating conditional If / Else Functoid Logic in a map.
By BiZTech Know
This article will explain how to create conditional If / Else logic in a BizTalk map using out of the box functoids. This example will take in a Xml file containing Films and their receipts and create a destination file whose structure id dependent on the incoming data.
BizTalk: Incorporating conditional If / Else Functoid Logic in a map.
This article will explain how to create conditional If / Else logic
in a BizTalk map using out of the box functoids. This example will take in a
Xml file containing Films and their receipts and create a destination file whose
structure id dependent on the incoming data.
Pre-requisites
This example assumes a good working knowledge of BizTalk, mapping, functoids
and schemas.
Create the source and destination schemas
Source Schema
Start up Visual Studio and create a new blank BizTalk project. Right click
the project file and add a new schema. Call it FilmReceipts.xsd. Add elements
to it until it resembles the screenshot below.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema targetNamespace="http://If_Else_Logic.FilmReceipts" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://If_Else_Logic.FilmReceipts" xmlns:b="http://schemas.microsoft.com/BizTalk/2003">
<xs:element name="FilmReceipts">
<xs:annotation>
<xs:appinfo>
<b:recordInfo rootTypeName="FilmReceipts"/>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Film" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FilmName" type="xs:string"/>
<xs:element name="Receipts" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
FilmReceipts.xsd source
Destination Schema
Add another xsd to the project and name it FilmsByReceipts.xsd. Add elements
to it until it resembles the screenshot below.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema targetNamespace="http://If_Else_Logic.FilmsByReceipts" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://If_Else_Logic.FilmsByReceipts" xmlns:b="http://schemas.microsoft.com/BizTalk/2003">
<xs:element name="FilmsByReceipts">
<xs:complexType>
<xs:sequence>
<xs:element name="BigFilms" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FilmName" type="xs:string"/>
<xs:element name="FilmReceipts" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NotSoBigfilms" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FilmName" type="xs:string"/>
<xs:element name="FilmReceipts" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
FilmByReceipts.xsd source
Create instance of input file
Next we need to create an instance of the input file that is based on FilmReceipts.xsd.
The easiest way to do this is to right click on FilmReceipts.xsd and select Create
instance… Examine the output window to determine where Visual Studio created
this file and open it in your favourite text editor. Edit the file until it resembles
the version below and then save it.
<ns0:FilmReceipts xmlns:ns0="http://If_Else_Logic.FilmReceipts">
<Film>
<FilmName>Big Film No.1</FilmName>
<Receipts>10000000000</Receipts>
</Film>
<Film>
<FilmName>Big Film No.2</FilmName>
<Receipts>80000000000</Receipts>
</Film>
<Film>
<FilmName>Not So Big film No.1</FilmName>
<Receipts>50000000</Receipts>
</Film>
<Film>
<FilmName>Not So Big film No.2</FilmName>
<Receipts>30000000</Receipts>
</Film>
<Film>
<FilmName>Not So Big film No.3</FilmName>
<Receipts>10000000</Receipts>
</Film>
</ns0:FilmReceipts>
Create BizTalk Map
Next we need to create the map that will utilise the schemas we just created.
Right click the BizTalk project file and select add->new item->map files.
Define the source schema as FilmReceipts.xsd and the destination schema as FilmsByReceipts.xsd
Add the functoids
Now we need to add the functoids that will create the conditional logic. First
drag a Greater Than functoid from the Logical Functoids pane and drop it on the
map. This is the key functoid as the value configured within this functoid will
be the condition which will decide whether a film is a Big Film or a Not So Big
film and will route the info to the destination schema accordingly.
From
the source schema, drag a connector from the Receipts node to the left side of
the Greater Than functoid. Now right click the Greater Than functoid and select
properties. In the properties window select the ellipses button to configure
the functoid inputs. In the dialog that appears you need to set the threshold
value. Do this by clicking the Insert new parameter button which is the second
from left. This adds a new blank parameter. Type in a value as shown in the following
screenshot.

Click OK to save and close.
Set up Mapping actions
The following steps set up the actions that depend upon the evaluation of
the Receipts node value against the Greater Than functoid value.
From
the Advanced functoid pane drag a Value Mapping functoid. From the map screenshot
above you can see we will need to add a few more functoids so give yourself plenty
of room. Drag a connection from the Greater Than functoid to the Left of the
Value Mapping functoid. Now drag a connection from the Receipts node in the source
schema to the left of the Value Mapping functoid. Connect the right of the Value
Mapping functoid to the FilmReceipts node under BigFilms in the destination schema.
Finally tell BizTalk to only create the BigFilms node in the destination schema
when the Receipts value is bigger than the value defined in the Greater Than
functoid by connecting the Greater Than functoid to the BigFilms node in the
destination schema.
The functoid configuration you’ve set up now
tells BizTalk that when the value of Receipts in the source is greater than the
value defined in the Greater Than functoid, route this data to the FilmReceipts
node under BigFilms in the destination schema. As both the Receipts and the FilmName
are needed in the destination schema, repeat the above steps for the FilmName
node. You should end up with a map configuration looking like this.

Set up condition mapping actions
To handle and route Receipts with a value less than that defined in the Greater
Than functoid we need to add a Not Equal functoid. Connect the Greater Than functoid
to the left of the Not Equal functoid. Right click the Not Equal functoid and
insert a new parameter. Configure its value to be ‘true’, as in the following
screenshot.

Click OK to save and close.
Not Equal functoid
Now we have to set up the conditional mapping actions for NotSoBigFilms, just
as for the BigFilms we did earlier.
Drag two more Value Mapping
functoids onto the map. Connect the FilmName node in the destination schema to
one and the Receipts node to the other. Connect the Not Equal functoid to each.
Now join the Value Mapping functoid that is connected to Receipts in the source
schema to the FilmReceipts node under NotSoBigFilms in the destination schema.
Do the same for the other Value Mapping functoid connected to the FilmName node
in the source schema and connect it to the NotSoBigFilms->FilmName node in
the destination schema.
Once again we need to tell BizTalk to route
the data for Receipts less than the value configured in the Greater Than functoid
to the NotSoBigFilms record in the destination schema. Do this by connecting
the Not Equal functoid to the NotSoBigfilms record node in the destination schema.
You
should end up with a set of functoids and connections looking like the following
screenshot.

Save the map.
Testing the map
All that remains to do is to test the map. To do this simply, without creating
an orchestration, send and receive ports etc. simply right click on the map and
select ‘properties.

In the dialog, set the TestMap Input Instance to the location of the
FilmReceipts.xml file you created from the source schema earlier. Click OK to
save and close the properties dialog.
Now right click on the map
and select ‘Test map’. The results of the test should appear in the output window
of Visual Studio. You should see a message similar to the one below
Invoking component...
Test Map used the following file: <file:///C:\Projects\If_Else_Logic\TestFiles\FilmReceipts.xml>
as input to the map.
Test Map success for map file C:\Projects\If_Else_Logic\IfElse.btm.
The output is stored in the following file: <file:///C:\Documents and Settings\User\Local Settings\Temp\_MapData\IfElse_output.xml>
Component invocation succeeded.
Click on the link that tells you where the map output is saved (highlighted
in yellow above) and you should see something like the following.
<ns0:FilmReceipts xmlns:ns0="http://If_Else_Logic.FilmReceipts">
<Film>
<FilmName>Big Film No.1</FilmName>
<Receipts>10000000000</Receipts>
</Film>
<Film>
<FilmName>Big Film No.2</FilmName>
<Receipts>80000000000</Receipts>
</Film>
<Film>
<FilmName>Not So Big film No.1</FilmName>
<Receipts>50000000</Receipts>
</Film>
<Film>
<FilmName>Not So Big film No.2</FilmName>
<Receipts>30000000</Receipts>
</Film>
<Film>
<FilmName>Not So Big film No.3</FilmName>
<Receipts>10000000</Receipts>
</Film>
</ns0:FilmReceipts>
If you play around with the values in the <Receipts /> nodes you should see the affects whenever you test the map.
This article
shows how to implement conditional If / Else logic in a BizTalk map using out
of the box functoids. This is a simple example but it shows the potential of
this simple yet powerful technique for constructing conditional statements within
a BizTalk map.
Happy programming.
Popularity (3472 Views)
Article Discussion: BizTalk: Incorporating conditional If / Else Functoid Logic in a map.