Stay organized with collections
Save and categorize content based on your preferences.
You can use a switch block as a selection mechanism that allows the value of
an expression to control the flow of a workflow's execution. If a value
matches, that condition's statement is executed.
If no matching expression is found, the workflow looks for an optional default
condition: - condition: true. This should be the last condition in the
switch block as they are evaluated in order and the first match found is
executed. If there is neither a match nor a default condition, the workflow
continues execution with the step that immediately follows.
Each switch block can include a maximum of 50 conditions. Each expression must
evaluate to true or false. (Learn how to define and use expressions.)
For example, you can control the order of a workflow's execution by using a
switch block to jump between steps
based on a conditional expression:
You might want a workflow to jump to a specific step when a condition is met.
These two samples execute steps depending on the value returned by the first
step of the workflow.
A switch structure can also be used to support direct execution of steps when a
condition is met, without jumping to other steps. This improves the readability
of a workflow by reducing the number of steps in the workflow definition.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# Conditions\n\nYou can use a `switch` block as a selection mechanism that allows the value of\nan expression to control the flow of a workflow's execution. If a value\nmatches, that condition's statement is executed.\n\nIf no matching expression is found, the workflow looks for an optional default\ncondition: `- condition: true`. This should be the last condition in the\n`switch` block as they are evaluated in order and the first match found is\nexecuted. If there is neither a match nor a default condition, the workflow\ncontinues execution with the step that immediately follows.\n\nEach `switch` block can include a maximum of 50 conditions. Each expression must\nevaluate to true or false. (Learn how to define and use [expressions](/workflows/docs/reference/syntax/expressions).)\n\nFor example, you can control the order of a workflow's execution by using a\n`switch` block to [jump](/workflows/docs/reference/syntax/jumps) between steps\nbased on a conditional expression: \n\n### YAML\n\n```yaml\n - STEP_NAME_A:\n switch:\n - condition: ${\u003cvar translate=\"no\"\u003eEXPRESSION_A\u003c/var\u003e}\n next: STEP_NAME_B\n - condition: ${\u003cvar translate=\"no\"\u003eEXPRESSION_B\u003c/var\u003e}\n next: STEP_NAME_C\n - condition: true\n next: STEP_NAME_C\n next: STEP_NAME_D\n \n```\n\n### JSON\n\n```json\n [\n {\n \"\u003cvar translate=\"no\"\u003eSTEP_NAME_A\u003c/var\u003e\": {\n \"switch\": [\n {\n \"condition\": \"${\u003cvar translate=\"no\"\u003eEXPRESSION_A\u003c/var\u003e}\",\n \"next\": \"\u003cvar translate=\"no\"\u003eSTEP_NAME_B\u003c/var\u003e\"\n },\n {\n \"condition\": \"${\u003cvar translate=\"no\"\u003eEXPRESSION_B\u003c/var\u003e}\",\n \"next\": \"\u003cvar translate=\"no\"\u003eSTEP_NAME_C\u003c/var\u003e\"\n }\n {\n \"condition\": true,\n \"next\": \"\u003cvar translate=\"no\"\u003eSTEP_NAME_C\u003c/var\u003e\"\n }\n ],\n \"next\": \"\u003cvar translate=\"no\"\u003eSTEP_NAME_D\u003c/var\u003e\"\n }\n }\n ]\n \n```\n\nYou can also nest multiple steps inside a `switch` block: \n\n### YAML\n\n```yaml\n - STEP_NAME_A:\n switch:\n - condition: ${\u003cvar translate=\"no\"\u003eEXPRESSION\u003c/var\u003e}\n steps:\n - STEP_NAME_B:\n ...\n - STEP_NAME_C:\n ...\n next: STEP_NAME_D\n \n```\n\n### JSON\n\n```json\n [\n {\n \"\u003cvar translate=\"no\"\u003eSTEP_NAME_A\u003c/var\u003e\": {\n \"switch\": [\n {\n \"condition\": \"${\u003cvar translate=\"no\"\u003eEXPRESSION\u003c/var\u003e}\",\n \"steps\": [\n {\n \"\u003cvar translate=\"no\"\u003eSTEP_NAME_B\u003c/var\u003e\": {\n ...\n }\n },\n {\n \"\u003cvar translate=\"no\"\u003eSTEP_NAME_C\u003c/var\u003e\": {\n ...\n }\n }\n ]\n }\n ],\n \"next\": \"\u003cvar translate=\"no\"\u003eSTEP_NAME_D\u003c/var\u003e\"\n }\n }\n ]\n \n```\n\nNote that the `steps` block is optional. It can contain the following:\n\n- [`assign`](/workflows/docs/reference/syntax/variables#assign-step)\n- [`call`](/workflows/docs/reference/syntax/calls)\n- [`for`](/workflows/docs/reference/syntax/iteration#for-in)\n- [`parallel`](/workflows/docs/reference/syntax/parallel-steps)\n- [`raise`](/workflows/docs/reference/syntax/raising-errors)\n- [`return`](/workflows/docs/reference/syntax/completing#using-return)\n- [`steps`](/workflows/docs/reference/syntax/steps)\n- [`switch`](/workflows/docs/reference/syntax/conditions)\n- [`try`](/workflows/docs/reference/syntax/catching-errors)\n\nFor more information about defining a workflow's order of execution, see\n[Jumps](/workflows/docs/reference/syntax/jumps) and\n[Control the order of execution in a workflow](/workflows/docs/controlling-execution-order).\n\nSamples\n-------\n\nThese samples demonstrate the syntax.\n\n### Conditional jumps to specific steps\n\nYou might want a workflow to jump to a specific step when a condition is met.\nThese two samples execute steps depending on the value returned by the first\nstep of the workflow.\n\n### YAML\n\n - first_step:\n call: http.get\n args:\n url: https://www.example.com/callA\n result: first_result\n - where_to_jump:\n switch:\n - condition: ${first_result.body.SomeField \u003c 10}\n next: small\n - condition: ${first_result.body.SomeField \u003c 100}\n next: medium\n next: large\n - small:\n call: http.get\n args:\n url: https://www.example.com/SmallFunc\n next: end\n - medium:\n call: http.get\n args:\n url: https://www.example.com/MediumFunc\n next: end\n - large:\n call: http.get\n args:\n url: https://www.example.com/LargeFunc\n next: end\n\n### JSON\n\n [\n {\n \"first_step\": {\n \"call\": \"http.get\",\n \"args\": {\n \"url\": \"https://www.example.com/callA\"\n },\n \"result\": \"first_result\"\n }\n },\n {\n \"where_to_jump\": {\n \"switch\": [\n {\n \"condition\": \"${first_result.body.SomeField \u003c 10}\",\n \"next\": \"small\"\n },\n {\n \"condition\": \"${first_result.body.SomeField \u003c 100}\",\n \"next\": \"medium\"\n }\n ],\n \"next\": \"large\"\n }\n },\n {\n \"small\": {\n \"call\": \"http.get\",\n \"args\": {\n \"url\": \"https://www.example.com/SmallFunc\"\n },\n \"next\": \"end\"\n }\n },\n {\n \"medium\": {\n \"call\": \"http.get\",\n \"args\": {\n \"url\": \"https://www.example.com/MediumFunc\"\n },\n \"next\": \"end\"\n }\n },\n {\n \"large\": {\n \"call\": \"http.get\",\n \"args\": {\n \"url\": \"https://www.example.com/LargeFunc\"\n },\n \"next\": \"end\"\n }\n }\n ]\n\n### YAML\n\n - getCurrentTime:\n call: http.get\n args:\n url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam\n result: currentTime\n - conditionalSwitch:\n switch:\n - condition: ${currentTime.body.dayOfWeek == \"Friday\"}\n next: friday\n - condition: ${currentTime.body.dayOfWeek == \"Saturday\" or currentTime.body.dayOfWeek == \"Sunday\"}\n next: weekend\n next: workWeek\n - friday:\n return: \"It's Friday! Almost the weekend!\"\n - weekend:\n return: \"It's the weekend!\"\n - workWeek:\n return: \"It's the work week.\"\n\n### JSON\n\n [\n {\n \"getCurrentTime\": {\n \"call\": \"http.get\",\n \"args\": {\n \"url\": \"https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam\"\n },\n \"result\": \"currentTime\"\n }\n },\n {\n \"conditionalSwitch\": {\n \"switch\": [\n {\n \"condition\": \"${currentTime.body.dayOfWeek == \\\"Friday\\\"}\",\n \"next\": \"friday\"\n },\n {\n \"condition\": \"${currentTime.body.dayOfWeek == \\\"Saturday\\\" or currentTime.body.dayOfWeek == \\\"Sunday\\\"}\",\n \"next\": \"weekend\"\n }\n ],\n \"next\": \"workWeek\"\n }\n },\n {\n \"friday\": {\n \"return\": \"It's Friday! Almost the weekend!\"\n }\n },\n {\n \"weekend\": {\n \"return\": \"It's the weekend!\"\n }\n },\n {\n \"workWeek\": {\n \"return\": \"It's the work week.\"\n }\n }\n ]\n\n### Switch structure with embedded steps\n\nA switch structure can also be used to support direct execution of steps when a\ncondition is met, without jumping to other steps. This improves the readability\nof a workflow by reducing the number of steps in the workflow definition.\n\n### YAML\n\n - step1:\n assign:\n - a: 1\n - step2:\n switch:\n - condition: ${a==1}\n steps:\n - stepA:\n assign:\n - a: ${a+7}\n - stepB:\n return: ${\"increase a to:\"+string(a)}\n - step3:\n return: ${\"default a=\"+string(a)}\n\n### JSON\n\n [\n {\n \"step1\": {\n \"assign\": [\n {\n \"a\": 1\n }\n ]\n }\n },\n {\n \"step2\": {\n \"switch\": [\n {\n \"condition\": \"${a==1}\",\n \"steps\": [\n {\n \"stepA\": {\n \"assign\": [\n {\n \"a\": \"${a+7}\"\n }\n ]\n }\n },\n {\n \"stepB\": {\n \"return\": \"${\\\"increase a to:\\\"+string(a)}\"\n }\n }\n ]\n }\n ]\n }\n },\n {\n \"step3\": {\n \"return\": \"${\\\"default a=\\\"+string(a)}\"\n }\n }\n ]"]]