Switch Routing

Use <switch> when one exact string selects a route.

Example

WOML
<switch id="delivery" value="{{context.steps.order.provider}}">
  <case value="express">
    <step id="express"><script>return { days: 1 };</script></step>
    <result value="{{context.steps.express}}" />
  </case>
  <default>
    <step id="standard"><script>return { days: 5 };</script></step>
    <result value="{{context.steps.standard}}" />
  </default>
</switch>

Matching is exact, case-sensitive, ordered, and has no fallthrough. Case values must be unique, and a final <default> is required.

An ID-bearing switch requires a result in every route and publishes at context.steps.<switchId>. An ID-less switch controls execution without a merged output.

Prepare the routing value

Return a normalized string from a preceding step:

WOML
<step id="selectDelivery">
  <script>
    const requested = context.payload.delivery ?? "standard";
    return { provider: requested.trim().toLowerCase() };
  </script>
</step>

Route on that stable result:

WOML
<switch id="delivery" value="{{context.steps.selectDelivery.provider}}">
  <case value="express">
    <step id="express"><script>return { days: 1 };</script></step>
    <result value="{{context.steps.express}}" />
  </case>
  <case value="standard">
    <step id="standard"><script>return { days: 5 };</script></step>
    <result value="{{context.steps.standard}}" />
  </case>
  <default>
    <step id="unsupported"><script>return { supported: false };</script></step>
    <result value="{{context.steps.unsupported}}" />
  </default>
</switch>

The runtime value must be a string. Matching performs no trim, normalization, numeric coercion, or fallthrough. Normalize user input before the switch when case or whitespace should not matter.

Choose switch instead of choose

Use switch when one exact category selects a route. Use choose when ordered boolean rules matter. Do not create several when steps that repeatedly compare the same status string; switch communicates that intent more clearly.

Case values must be unique and the final default is required. A result-producing switch gives downstream work one predictable output regardless of which case ran.