Search code examples
muledataweavemulesoftmule-esb

if else statement Mule 3


I want to set a variable based on the output in Mule 3.

For example the check I want to do is if there is any payload I want to set the var value to this ${http.path.one} else ${http.path.two}. In Mule 4 it can be done in multiple ways but in Mule 3 seems little tricky. Has anyone an idea how to implement this in Mule 3?


Solution

  • In Mule 3 DataWeave you can use when/otherwise instead of Mule 4 if/else. To access the properties use the p() function. Depending on the exact payload and the condition you need you may need to tweak the expression for the condition.

    Example:

    p('http.path.two') when (payload != null) otherwise p('http.path.one')