How do I implement IF in mulesoft

ReganJohnson picture ReganJohnson · Mar 17, 2015 · Viewed 8.4k times · Source

I want to make a decision in a Mulesoft flow, and have looked at the Choice Flow Control. My problem, is that I want to do something if the condition is true, and nothing if it is false, something like:

if (condition == true)
   do some work

or, in probably incorrect xml:

<choice doc:name="call a subflow if the test is true">
    <when expression="#[flowVars.someVariable == True]">
        <flow-ref name="doSomething" doc:name="do another thing"/>
    </when>
</choice>

no else clause, and no default flow. How is this implemented in a Mulesoft flow? I could cheat, and throw a logging call into a default flow, but I would prefer not to.

Answer

Ryan Carter picture Ryan Carter · Mar 17, 2015

Unfortunately there is no simple 'if' processor in Mule. Choice with a dummy otherwise route or filters are the way to go for now.

There is a good discussion on this here: https://www.mulesoft.org/jira/browse/MULE-6129. THis has further links to possible enhancements such as an if/detour router.

Mule 4 UPDATE

In mule 4, you can now define a choice router with no need for an otherwise route. And filters no longer exist