Skip to main content
Skip table of contents

choose

The choose command creates a set of conditional sections, of which only one will have its commands evaluated.

There should be one or more when commands as children, each with its own condition. If the condition of one of them evaluates to a Boolean true, the children of that when are evaluated and the remaining children of choose are skipped. Otherwise, that when is skipped and the condition of the next when command is evaluated.

The last child of choose may be an otherwise command. Its contents will be processed if all the preceding when commands were skipped.

Child commands

  • when
    Required. At least one of these is required to be among choose's children.

  • otherwise
    Optional. One otherwise can be a child of choose. Preferably as the last child after the when commands.

Examples

The choose command must be used with the when and otherwise commands as its children.

image-20241202-134407.png
CODE
<choose>
        <when test="${oppLineItem.Quantity >= 1000}">
          <set var="quantityDesc" value="High">
        <when test="${oppLineItem.Quantity < 10}">
          <set var="quantityDesc" value="Low">
        <otherwise>
          <set var="quantityDesc" value="Medium">

Note that the order of the child commands matters. The otherwise command always finishes the evaluation of choose, so any when commands after an otherwise never do anything. In this example of how not to do things, the "response" variable will never end up having "Yes." as its value.

image-20241202-134530.png
CODE
<choose>
        <otherwise>
          <set var="response" value="No. Ask again later.">
        <when test="${areWeThereYet}">
          <set var="response" value="Yes.">
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.