Sunday, March 8, 2009

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


Sunday, March 8, 2009 10:02:37 PM (Romance Standard Time, UTC+01:00)  #    Comments [2]  | 
Wednesday, March 11, 2009 11:26:56 AM (Romance Standard Time, UTC+01:00)
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.

Wednesday, March 11, 2009 8:34:15 PM (Romance Standard Time, UTC+01:00)
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.

All comments require the approval of the site owner before being displayed.
Please login with either your OpenID above, or your details below.
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview

Theme design by Jelle Druyts