TimRayburn.CustomFunctoids - If ... Else
This post is part of an ongoing series, the explanation of which can be found here.
This one should be of more use to our friends using BizTalk Server 2006. Today we tackle a problem that anyone who has ever mapped an EDI 837 I/P/D has had to deal with, and probably solved with hundreds of "Value Mapping" functoids and Logical Not (if you are on 2006) functoids.
The out of the box functoid set gives you a very nice "Value Mapping" functoid which is great because it compiles to an xsl:if tag. But if you want to do a simple If A then B else C type logic you are left with either two value map functoids and a Logical Not (or Logical Equal in 2004) functoids, or you are writing a scripting functoid. Either way you have hampered the readability of your map, and in the case of the value map solution you've netted yourself a compiler warning for two links to one node for each and every node you had to do this with. If it is an 837 that you're doing this with, that is a TON of nodes in the 2300 and 2400 loops.
The solution? IfElseFunctiod of course! This class, added to the TimRayburn.CustomFunctoids project, takes three parameters. The first is a boolean, the second is the value returned if true, the third is the value returned if false. It is important to note that in any case, if connected directly to the output schema this will produce a node. It is not a XSLT functoid and cannot suppress the output node. For now if you need to do that, you're still stuck with putting in a Value Mapping functoid.
The newly added class can be found below. It is nearly identical to last night's functoid of course. Interestingly, I tried to refactor this class and the other to create a base class that handled assigning the ID and resources. When I did so, BizTalk stopped recognizing that the assembly contained any functoids. Apparently your custom functoids must not simply inherit from BaseFunctoid, they must be direct children of BaseFunctoid.
10 class IfElseFunctoid : BaseFunctoid
12 public IfElseFunctoid()
14 // Assign a "unique" id to this functiod
15 this.ID = 24602;
17 // Setup the resource assembly to use.
34 this.Category = FunctoidCategory.ValueMapping;
35 this.OutputConnectionType = ConnectionType.AllExceptRecord;
42 public string IfElse(string booleanValue, string trueValue, string falseValue)
44 bool bVal = System.Convert.ToBoolean(booleanValue);
45 if (bVal)
46 return trueValue;
48 return falseValue;