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

by eliasen 8. March 2009 21:02

Hi all

So, I have written two previous posts about how to solve the If-Then-Else problem in a map. The first post discussed the way to use built-in functoids to solve the issue. The second post discussed the issues I had creating a custom functoid to do the job.

Well, I now have a new way of doing it, which is not just one functoid, but still it's prettier than what I can do with the built-in functoids.

Basically, as discussed in my post about the issues with the different functoid categories, a functoid that is in the String category cannot accept a logical functoid as input. A scripting functoid can accept a logical functoid as input, but I can't create a custom scripting functoid where I decide what script to appear inside the scripting functoid at design time.

So the solution I am describing in this post is a combination of the two.

This screenshot describes a map that solves the If-Then-Else problem:


The blue functoid with the crappy icon is programmed by myself. It is a simple functoid, which takes in three parameters, which are all strings. First, it tries to convert the first parameter to a boolean. If this fails, a "false" is assumed. Then, if the boolean was true, the second parameter is returned and if it was false, the third parameter is returned.

Now, since a string functoid cannot take a logical functoid as an input, I use a custom scripting functoid that is very simple:

public string Same(string str)
return str;

Which is really annoying to have to do, since... well... I take in a string and return the exact same string. Oh well...

You can find my functoid and the project that uses it as file downloads at the bottom of this post. Note, that the functoid library contains a whole bunch of functoids, of which only one is relevant. The library contains all the functoids I built trying to solve the If-Then-Else issue. The only needed functoid will be included in my downloadable functoid library at a later point.

Now, the advantages of this solution is, that it only requires three functoids all together. The best I could do with the built-in functoids were four, and five were sometimes the prettiest solution.

Functoid library: here

Project that uses the functoid: here



Comments (2) -

Henrik Jørgensen
Henrik Jørgensen
3/11/2009 10:26:56 AM #

Hi Jan,

I've just done If-then-else in a third way: Using a table looping functoid with gating, as I had two outputs to be generated. It's fairly easy to read the structure that way.

I actually found a bug in Biztalk mapping in the process, as I used the 'greater than' looping functoid on dates:
It might be string evaluation that got the better of me when I passed datetime to the greater than functiod:
1/1/3000 12:00:00 AM > 1/15/2009 12:00:00 AM
TRUE, no problem
1/13/2009 12:00:00 AM > 1/1/3000 12:00:00 AM
TRUE, whoops

(I hope I set the > correctly above, as the dates are out of a test set I preserved for doing a post mortem) I haven't had time to play with where precisely the bug arises, I just entered the dates into a script functoid, converted and compared, so bear with me with the above. Anyway now the word of caution is out there: Built-in functoids and DateTime is a no-no.


Jan Eliasen
Jan Eliasen
3/11/2009 7:34:15 PM #

Hi Henrik

Probably, the issue with the comparisons is, that basically, inputs and outputs to funoids are treated as strings. And naturally, there can be quite a difference between how two DateTime are compared and how their string representations are compared.

Anyway, thanks for the tip about the table looping solution.



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