Solving the "If-Then-Else" problem in a map - part I

by eliasen 15. november 2008 20:49

Hi all

I have often wondered why the built-in functoids doesn't encompass an If-Then-Else functoid. The Value Mapping functoid only has an If-Then-part and not the Else-part.

This is the first of two blog posts. This post will explore how to solve the issue with the built-in functionality of BizTalk. The next post will be about creating a custom functoid to do the job instead and the issues that come with this task.

So, using the built-in functionality:

Imagine this input schema:


And imagine this output schema:


My goal, now is to create a map that will map the value of the "ifJan" element to the destination IF the "qualifier" element equals the word "Jan" and otherwise the value of the "ifNotJan" element should be mapped.

So basically, given this input:

<ns0:IfThenElseInput xmlns:ns0="http://IfThenElse.IfThenElseInput">

I want this output:

<ns0:IfThenElseOutput xmlns:ns0="http://IfThenElse.IfThenElseOutput">

And given this input:

<ns0:IfThenElseInput xmlns:ns0="http://IfThenElse.IfThenElseInput">

I want this output:

<ns0:IfThenElseOutput xmlns:ns0="http://IfThenElse.IfThenElseOutput">

Using a map and the built-in functoids, that would look like this:


Basically, you need one value mapping functoid for each possible value to pass on, and a logical functoid for each value as well, to use in the value mapping functoid. The "String Concatenate" functoid is just my way of returning the string to use for the qualifier - in this case: "Jan".

You can also do it using one scripting functoid like this:


where the scripting functoid is an "Inline XSLT Call Template" scripting type, and the script looks likes this:

<xsl:template name="IfThenElse">
  <xsl:param name="qualifier" />
  <xsl:param name="ifJan" />
  <xsl:param name="ifNotJan" />
  <xsl:element name="field">
      <xsl:when test="$qualifier='Jan'">
        <xsl:value-of select="$ifJan" />
        <xsl:value-of select="$ifNotJan" />

Now... IF my good friend Henrik Badsberg is reading this, then by now he is screaming: "USE A BLOODY C# SCRIPTING FUNCTOID!!!!!" :-)

This, naturally is also an option:


with an "Inline C#" script containing this script:

public string IfThenElse(string qualifier, string ifJan, string ifNotJan)
  if (qualifier == "Jan")
    return ifJan;
    return ifNotJan;

Both scripting solutions can be altered to accept the output of a logical functoid as the first input. Just change the string "Jan" to "true" in the scripts, and change the name of the parameter if you want.

Now then... I am not a big fan of either of these three options. Generally, I avoid scripting functoids when I can because it is difficult for a new developer to know what is happening when he opens the map because he will have to open up all scripting functoids and find out (and remember) what they do. Also, I am not really a big fan of the first solution either. First of all, there are too many functoids, and it can messy if this solution is needed several times in a map. Secondly, you get a warning every time you compile, because you have two inputs to one element.

You can find my project with the three working maps here.

In my next post, I will look into creating a custom functoid that does the job and I can tell you right now; That isn't as easy as I had imagined...



BizTalk 2004 | BizTalk 2006

Add comment

  Country flag

  • Comment
  • Preview

About the author

Jan Eliasen is 37 years old, divorced and has 2 sons, Andreas (July 2004) and Emil (July 2006).

Jan has a masters degree in computer science and is currently employed at Logica Denmark as an IT architect.

Jan is a 6 times Microsoft MVP in BizTalk Server (not currently an MVP) and proud co-author of the BizTalk 2010 Unleashed book.

BizTalk Server 2010 Unleashed

Buy from Amazon

Microsoft MVP

6 times: July 2004, July 2008, July 2009, July 2010, July 2011, and July 2012. Not currently an MVP.


Image to show

Month List

Page List