If/ElseIf/Else

The If/ElseIf/Else actions execute actions if a condition is satisfied.

The If/ElseIf/Else actions execute nested actions based on one or more mutually-exclusive conditions:

  • "If" conditions are always checked.
  • "ElseIf" conditions are only checked if all preceding "If" and "ElseIf" conditions were not satisfied.
  • "Else" actions have no condition; if none of the preceding "If" or "ElseIf" conditions were satisfied, the "Else" actions are automatically executed.

The following table shows the parameters for the If action.

Table 1. If action parameters
Name Data type Required Notes
condition JPath Yes The condition to evaluate. Cannot be empty.
actions Actions[] Yes The sequence of actions to execute if the condition is true. Cannot be empty.

The following table shows the parameters for the ElseIf action.

Table 2. ElseIf action parameters
Name Data type Required Notes
condition JPath Yes The condition to evaluate. Cannot be empty.
actions Actions[] Yes The sequence of actions to execute if the condition is true. Cannot be empty.

The following table shows the parameters for the Else action.

Table 3. Else action parameters
Name Data type Required Notes
actions Actions[] Yes The sequence of actions to execute if none of the preceding "If" or "ElseIf" conditions are true. Cannot be empty.

XML Example

In this example, the following actions are taken:

  • If the State value at location /status is 200, only the SetStatus action that sets the status to an INFO "Success" message is executed.
  • If the /status value is 401, only the SetStatus action that sets the status to an ERROR "Authentication Failure" message is executed.
  • If the /status value is 404, only the SetStatus action that sets the status to an ERROR "No Route Exists" message is executed.
  • If the /status value is anything else, only the final SetStatus action is executed.
<If condition="/status = 200">
    <SetStatus type="INFO" message="Success." />
</If>
<ElseIf condition="/status = 401">
    <SetStatus type="ERROR" message="Authentication Failure." />
</ElseIf>
<ElseIf condition="/status = 404">
    <SetStatus type="ERROR" message="No Route Exists." />
</ElseIf>
<Else>
    <SetStatus type="ERROR" message="An unknown error (${/status}) has occurred." />
</Else>