The Choice flow control component dynamically routes execution based on the contents of its input. It adds conditional processing to a flow, similar to an
else code block in most programming languages.
A Choice flow control component uses expressions written in DataWeave language to evaluate the content of the input. It then routes to the first option that matches the expression (evaluates to
A When (
when) block is executed when the input matches its condition.
The Otherwise (
otherwise) block is executed by default if none of the conditions match the When block.
Here, the top routing conditions are set by
when blocks, while the default is set by an
In this simple example, the Choice router is returns a message in one of three languages depending on the value of a
language variable in the Mule event.
Note that you can provide a custom name to each condition, which only affects what you see in the editor, not the behavior of the app.
The configuration for this router shows the DataWeave used for the conditional processing:
#[vars.language == 'french']
#[vars.language == 'spanish']
Defaultto reply in English.
The components within the router set the value of the response. So, if the value of the
language variable is
spanish, the output might be
Hola! instead of the French or English greetings.