Orkes logo image
Product
Platform
Orkes Platform thumbnail
Orkes Platform
Agentspan thumbnail
Agentspan
Orkes Conductor Vs Conductor OSS thumbnail
Orkes vs. Conductor OSS
Orkes Cloud
Try enterprise Orkes Cloud for free
Enjoy a free 14-day trial with all enterprise features
Start for free
Capabilities
Microservices Workflow Orchestration icon
Microservices Workflow Orchestration
Enable faster development cycles, easier maintenance, and improved user experiences.
Realtime API Orchestration icon
Realtime API Orchestration
Enable faster development cycles, easier maintenance, and improved user experiences.
Event Driven Architecture icon
Event Driven Architecture
Create durable workflows that promote modularity, flexibility, and responsiveness.
Human Workflow Orchestration icon
Human Workflow Orchestration
Seamlessly insert humans in the loop of complex workflows.
Process orchestration icon
Process Orchestration
Visualize end-to-end business processes, connect people, processes and systems, and monitor performance to resolve issues in real-time
Agentic workflows icon
Agentic Workflows
Transform your workflows into agentic experiences while maintaining full compliance and control
Use Cases
By Industry
Financial Services icon
Financial Services
Secure and comprehensive workflow orchestration for financial services
Media and Entertainment icon
Media and Entertainment
Enterprise grade workflow orchestration for your media pipelines
Telecommunications icon
Telecommunications
Future proof your workflow management with workflow orchestration
Healthcare icon
Healthcare
Revolutionize and expedite patient care with workflow orchestration for healthcare
Shipping and logistics icon
Shipping and Logistics
Reinforce your inventory management with durable execution and long running workflows
Software icon
Software
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean leo mauris, laoreet interdum sodales a, mollis nec enim.
Docs
Developers
Learn
Blog
Explore our blog for insights into the latest trends in workflow orchestration, real-world use cases, and updates on how our solutions are transforming industries.
Read blogs
Check out our latest blog:
How to Reuse Workflows Inside Other Workflows in Orkes Conductor
Customers
Discover how leading companies are using Orkes to accelerate development, streamline operations, and achieve remarkable results.
Read case studies
Our latest case study:
LinkedIn Case Study Thumbnail
Orkes Academy New!
Master workflow orchestration with hands-on labs, structured learning paths, and certification. Build production-ready workflows from fundamentals to Agentic AI.
Explore courses
Featured course:
Orkes Academy Thumbnail
Events icon
Events
Videos icons
Videos
In the news icon
In the News
Whitepapers icon
Whitepapers
About us icon
About Us
Pricing
Get a demo
Signup
Slack FaviconDiscourse Logo icon
Get a demo
Signup
Slack FaviconDiscourse Logo icon
Orkes logo image

Company

Platform
Careers
HIRING!
Partners
About Us
Legal Hub
Security

Product

Cloud
Platform
Support

Community

Docs
Blogs
Events

Use Cases

Microservices Workflow Orchestration
Realtime API Orchestration
Event Driven Architecture
Agentic Workflows
Human Workflow Orchestration
Process Orchestration

Compare

Orkes vs Camunda
Orkes vs BPMN
Orkes vs LangChain
Orkes vs Temporal
Twitter or X Socials linkLinkedIn Socials linkYouTube Socials linkSlack Socials linkGithub Socials linkFacebook iconInstagram iconTik Tok icon
© 2026 Orkes. All Rights Reserved.
Back to Blogs

Table of Contents

Share on:Share on LinkedInShare on FacebookShare on Twitter
Worker Code Illustration

Get Started for Free with Dev Edition

Signup
Back to Blogs
ENGINEERING

How to Add Conditional Branching to Your Workflows in Orkes Conductor

Maria Shimkovska
Maria Shimkovska
Content Engineer
Last updated: June 18, 2026
June 18, 2026
3 min read

Related Blogs

How to Reuse Workflows Inside Other Workflows in Orkes Conductor

Jun 24, 2026

How to Reuse Workflows Inside Other Workflows in Orkes Conductor

How to Process a List of Items in Parallel in Orkes Conductor

Jun 20, 2026

How to Process a List of Items in Parallel in Orkes Conductor

How to Call Any External API From a Workflow in Orkes Conductor

Jun 17, 2026

How to Call Any External API From a Workflow in Orkes Conductor

Ready to Build Something Amazing?

Join thousands of developers building the future with Orkes.

Start for free

This is for you if you would prefer not to read documentation and see more examples.

I want to show you everything that's possible with the built-in tasks in Orkes Conductor.

This is part of a series covering every built-in task in Orkes Conductor. This one is for the SWITCH task.


Cover for the Switch task article, showing a simple workflow running successfully in Orkes Conductor

What is the Switch task?

The SWITCH task evaluates a value from a workflow input, a previous task's output, or an inline expression and routes execution to the matching branch.

Each branch is its own sequence of tasks. If no branch matches, it falls through to a default case.

Why does this matter? Because a lot of workflows you will build are non-linear and need to take different paths depending on something else. Like payments needing to get flagged, orders shipping to different regions, support tickets needing to go to different teams depending on severity, and more.

Without a built-in way to handle that, you end up writing more workflows than you need or burying decision logic in your codebase.


Three Real-World Examples

1. Route a File Upload to the Right Processing Service

If you're building a file upload workflow, where users can upload images, PDFs, and videos but each file type needs to go to a completely different processing service (images, for examples, need compression, PDFs need text extraction, and videos need some type of transcoding), then you would need a step that reads the file type and sends it to the right place.

This is where you can use the Switch task for:

json
{
  "name": "route_by_file_type",
  "taskReferenceName": "route_by_file_type_ref",
  "type": "SWITCH",
  "evaluatorType": "value-param",
  "expression": "fileType",
  "inputParameters": {
    "fileType": "${workflow.input.fileType}"
  },
  "decisionCases": {
    "image": [
      {
        "name": "compress_image",
        "taskReferenceName": "compress_image_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://processing.internal/compress",
          "method": "POST",
          "body": { "fileUrl": "${workflow.input.fileUrl}" }
        }
      }
    ],
    "pdf": [
      {
        "name": "extract_text",
        "taskReferenceName": "extract_text_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://processing.internal/extract",
          "method": "POST",
          "body": { "fileUrl": "${workflow.input.fileUrl}" }
        }
      }
    ],
    "video": [
      {
        "name": "transcode_video",
        "taskReferenceName": "transcode_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://processing.internal/transcode",
          "method": "POST",
          "body": { "fileUrl": "${workflow.input.fileUrl}" }
        }
      }
    ]
  },
  "defaultCase": []
}

The file type comes in as a workflow input, the SWITCH reads it, and the right processing service gets called. One workflow handles every file type you don't need a separate workflow for images, another for PDFs, and another for videos.

The JSON code for the Switch task can be longer than other Conductor tasks, but that's because you need to also account for the different paths, like the image, pdf, and video. You can see them in the JSON snippet above.


2. Send a Notification on the Channel the User Actually Wants

If you're building a notification workflow, where some users want email, some prefer SMS, and others have set up Slack, then you would need a step that checks the user's preference and sends the message to the right place.

Here is what this could look like in your workflow definition:

json
{
  "name": "route_by_channel",
  "taskReferenceName": "route_by_channel_ref",
  "type": "SWITCH",
  "evaluatorType": "value-param",
  "expression": "preferredChannel",
  "inputParameters": {
    "preferredChannel": "${get_user_prefs_ref.output.response.body.notificationChannel}"
  },
  "decisionCases": {
    "email": [
      {
        "name": "send_email",
        "taskReferenceName": "send_email_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://notifications.internal/email",
          "method": "POST",
          "body": { "to": "${workflow.input.email}", "message": "${workflow.input.message}" }
        }
      }
    ],
    "sms": [
      {
        "name": "send_sms",
        "taskReferenceName": "send_sms_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://notifications.internal/sms",
          "method": "POST",
          "body": { "phone": "${workflow.input.phone}", "message": "${workflow.input.message}" }
        }
      }
    ],
    "slack": [
      {
        "name": "send_slack",
        "taskReferenceName": "send_slack_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://notifications.internal/slack",
          "method": "POST",
          "body": { "slackId": "${workflow.input.slackId}", "message": "${workflow.input.message}" }
        }
      }
    ]
  },
  "defaultCase": []
}

The workflow reads the user's saved preference and calls the right notification service.

The message is the same only the delivery method changes. Without the SWITCH task, you'd be writing that if/else yourself somewhere in your application code.


3. Handle Sign Up Differently Based on How the User Registered

Ah, a classic example we are all familiar with.

If you're building a signup workflow, where users can register with Google, with their email and password, or through SSO via their company, then each path needs different steps Google sign ups need an OAuth token exchange, email sign ups need a password to be hashed and stored, SSO sign ups need to be validated against the company's identity provider.

json
{
  "name": "route_by_auth_method",
  "taskReferenceName": "route_by_auth_ref",
  "type": "SWITCH",
  "evaluatorType": "value-param",
  "expression": "authMethod",
  "inputParameters": {
    "authMethod": "${workflow.input.authMethod}"
  },
  "decisionCases": {
    "google": [
      {
        "name": "exchange_google_token",
        "taskReferenceName": "google_oauth_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://auth.internal/google/exchange",
          "method": "POST",
          "body": { "code": "${workflow.input.oauthCode}" }
        }
      }
    ],
    "email": [
      {
        "name": "create_email_account",
        "taskReferenceName": "email_signup_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://auth.internal/email/register",
          "method": "POST",
          "body": { "email": "${workflow.input.email}", "password": "${workflow.input.password}" }
        }
      }
    ],
    "sso": [
      {
        "name": "validate_sso",
        "taskReferenceName": "sso_ref",
        "type": "HTTP",
        "inputParameters": {
          "uri": "https://auth.internal/sso/validate",
          "method": "POST",
          "body": { "samlToken": "${workflow.input.samlToken}", "domain": "${workflow.input.domain}" }
        }
      }
    ]
  },
  "defaultCase": []
}

With a built-in Switch task one signup workflow can handle every authentication method you want to support.

The SWITCH reads how the user registered and calls the right service.

Whatever comes after creating the user's profile, sending a welcome email, setting up their workspace runs the same way regardless of how they got in.


What the Task Returns

The SWITCH task itself doesn't return data. The tasks inside the branch that ran return their own outputs as normal.

The one thing the SWITCH does return is selectedCase, which tells you which branch was taken:

json
${route_by_file_type_ref.output.selectedCase}

One thing to know: if no branch matches and defaultCase is [], the workflow keeps going without failing. It just skips the SWITCH task and moves to the next task in your workflow.


When Should You Reach for This Task?

We built this task so your branching logic lives inside the workflow, not in your codebase.

Any time your workflow needs to take a different path based on a value, a score, a status, or a condition, the SWITCH task handles it natively.

If you're about to write an if/else in a custom worker just to decide which API to call next, you can just use the built-in task, simplfying your own code.


Try It Yourself

The fastest way to see this in action is to spin up a free Developer Edition account of Orkes Conductor.

  1. Create your free Developer Edition account
  2. Go to Definitions > Workflow and click + Define Workflow
  3. Paste in the workflow below in the Code tab and hit Execute. I built this small workflow so you can just copy, paste, and see it run:

I Built This So You Can Just Copy, Paste, and See It Run

This workflow fetches the current weather for any city using a public API, then uses a SWITCH task to route to a different outcome based on whether it's hot, mild, or cold. Just paste this into Conductor and hit Execute. It will build and run right away.

json
{
  "name": "weather_routing_example",
  "description": "Fetches current weather for a city and routes based on temperature using a SWITCH task.",
  "version": 1,
  "tasks": [
    {
      "name": "get_weather",
      "taskReferenceName": "get_weather_ref",
      "type": "HTTP",
      "inputParameters": {
        "uri": "https://api.open-meteo.com/v1/forecast?latitude=${workflow.input.latitude}&longitude=${workflow.input.longitude}&current_weather=true",
        "method": "GET",
        "accept": "application/json"
      }
    },
    {
      "name": "categorise_temperature",
      "taskReferenceName": "categorise_temp_ref",
      "type": "INLINE",
      "inputParameters": {
        "evaluatorType": "graaljs",
        "expression": "(function() { var temp = $.temp; if (temp >= 25) return 'hot'; if (temp >= 15) return 'mild'; return 'cold'; })();",
        "temp": "${get_weather_ref.output.response.body.current_weather.temperature}"
      }
    },
    {
      "name": "route_by_temperature",
      "taskReferenceName": "route_by_temp_ref",
      "type": "SWITCH",
      "evaluatorType": "value-param",
      "expression": "tempCategory",
      "inputParameters": {
        "tempCategory": "${categorise_temp_ref.output.result}"
      },
      "decisionCases": {
        "hot": [
          {
            "name": "hot_weather_task",
            "taskReferenceName": "hot_ref",
            "type": "SET_VARIABLE",
            "inputParameters": {
              "recommendation": "It's hot outside. Stay hydrated."
            }
          }
        ],
        "mild": [
          {
            "name": "mild_weather_task",
            "taskReferenceName": "mild_ref",
            "type": "SET_VARIABLE",
            "inputParameters": {
              "recommendation": "Great weather for a walk."
            }
          }
        ],
        "cold": [
          {
            "name": "cold_weather_task",
            "taskReferenceName": "cold_ref",
            "type": "SET_VARIABLE",
            "inputParameters": {
              "recommendation": "Bundle up it's cold out there."
            }
          }
        ]
      },
      "defaultCase": []
    }
  ],
  "inputParameters": [
    "latitude",
    "longitude"
  ],
  "outputParameters": {
    "temperature": "${get_weather_ref.output.response.body.current_weather.temperature}",
    "category": "${categorise_temp_ref.output.result}"
  },
  "schemaVersion": 2,
  "restartable": true,
  "workflowStatusListenerEnabled": false,
  "timeoutPolicy": "ALERT_ONLY",
  "timeoutSeconds": 0
}

The workflow fetches the live temperature, categorises it with an INLINE task, and the SWITCH task routes to the matching branch. You can see exactly which path was taken in the Conductor UI the moment it finishes.

The routing, the branching, the conditional paths are already handled. The code you write is your business logic.


This is part of a series covering every built-in task in Orkes Conductor. Next up: the Inline task.