Monday, February 07, 2005

If...Then...Else

A common operation within maps is to inject a default value into the output schema if the the input field is blank / missing, otherwise just copy over the value.

This is a bit of a nightmare using the standard Logical Existance functoid, and is much more easily accomplished using inline C#. Simply added a script functoid, connect the input field as the first parameter, add a second parameter set to the default value, then use the following function:

public string IfThenElse(string param1, string param2)
{
return (param1 == null || param1.Length == 0) ? param2 : param1;
}

Then simply connect the output of this script functoid to your output field.

2 comments:

Anonymous said...

Unfortunately, your solution does not work.

Its VERY wierd that the logical exist functoid cant return a false.

Anonymous said...

Let me elaborate, it doesnt work if the node doesnt exist in some shape or form in the source document.