When coming from a programmer’s background, we are used to conditions evaluating Boolean variables directly. Unfortunately, this isn’t true for the evaluation of conditions of the structured activity IF for conditional branching in Oracle SOA Suite 11g based implementation of BPEL 2.0 business processes. Let us first have a look on a Java example first.

boolean boolVar;
if(boolVar) {
  System.out.println("Condition evaluates to true. Input value was "+boolVar.toString());
} else {
  System.out.println("Condition evaluates to false. Input value was "+boolVar.toString());
}

If the value of a Boolean variable is true, the condition based on this variable evaluates to true automatically. Similary, a Boolean variable of value false evaluates the condition to false. The BPEL 2.0 engine of Oracle SOA Suite 11g works differently: In BPEL Boolean variables will be converted to its string value prior to the condition evaluation. BPEL is using the XSLT function value-of. This means a Boolean variable value true becomes „true“. With a condition based only on the Boolean input variable,

<condition>$inputVariable.payload/ns1:BooleanInput</condition>

we end up with a string value „true“ or „false“ which ain’t compared to anything and therefore the condition evaluates to true. So even if the value of our Boolean input variable is set to the Boolean false, our condition becomes true. The correct answer to this behavior is to compare the binary input value to the desired text value that the Boolean input will be converted to.

<condition>$inputVariable.payload/ns1:BooleanInput = 'true'</condition>

The same way, compare your Boolean input to false  if you want to evaluate the boolean condition to true if the input value is false.

<condition>$inputVariable.payload/ns1:BooleanInput = 'false'</condition>

On the other hand, it is possible to directly evaluate a condition based on the XSLT function for true or false, if it is the only parameter of the condition.

<condition>true()</condition>

… evaluates to true.

<condition>false()</condition>

… evaluates to false, hence the else branch is selected. But this is only working if the Boolean function is the only paramter of the condition. If we use it in an evaluation against another parameter, the string representation will be used for comparison. The following condition …

<condition>$inputVariable.payload/ns1:BooleanInput = true()</condition>

… results in the string value of the Boolean input variable „true“ / „false“ being compared to the string representation „true()“ of the XSLT function true(). While „true“ != „true()“, the condition evaluates to false (else branch) even that we would expect the opposite. The same way, you cannot use the XSLT function true() respectivly false() indirectly to pass in true or false via a variable.

<assign name="AssignTrue">
  <copy>
    <from>false()</from>
    <to>$inputVariable.payload/ns1:BooleanInput</to>
  </copy>
</assign>
<if name="TrueOrFalse">
  <documentation>
    <![CDATA[true]]>
  </documentation>
  <condition>$inputVariable.payload/ns1:BooleanInput</condition>

On passing in the value of the Boolean varible to the condition, its string representation will be used to evaluate the condition. The following table summerizes this behavior:

Table 1 : Conditional Branching evaluation based on input
Value of $BooleanInput variable Condition Condition evaluation
true $BooleanInput true
false $BooleanInput true
true() true
false() false
true $BooleanInput = ‚true‘ true
false $BooleanInput = ‚true‘ false
true $BooleanInput = ‚false‘ false
false $BooleanInput = ‚false‘ true

Long story short: Compare Boolean variables agaist their string value.