xFlow
  • Overview
    • Introduction
    • Core Features
    • Architecture
      • High Level Architecture
      • Tech Stack
      • Deployment Flexibility
      • Performance and Scalability
      • Security Compliance
  • Getting Started
    • Installation
    • Quick Start
    • Configuration
  • Core Concepts
    • Serverless Workflow Specification
    • Workflow data handling
    • Workflow Expressions
    • Error handling
    • Input and Output schema definition
    • User Task
    • User Forms
      • Lowcode Form
      • Advanced User Form
    • AI Agents in Enterprise Business Processes
    • Comparisons
      • BPMN2
  • Developer Guide
    • Architecture
    • API Reference
    • Workflow States Reference
      • Event State
      • Operation State
      • Switch State
      • Parallel State
      • Inject State
      • ForEach State
      • Callback State
      • UserTask State
      • AIAgent State
      • AIAgentProxy State
      • UserProxyAgent State
      • AI Outbound Agent State
    • Workflow Functions
      • REST
      • GraphQL
      • Custom
        • Built-in Functions
        • Lowcoder Query Function
      • Function Auth
    • Workflow Secrets
    • Integrations
    • Workflow Modeler
    • Frontend Development
      • Forms
        • Lowcode Form
        • Advanced User Form
    • Serverless Workflow Development
      • Operation State
      • Switch State
      • Parallel State
      • ForEach State
      • Callback State
      • User Task State
    • AI Agent Development
      • AI Agent
        • Predefined LLM
        • LLM Configuration
        • Multi LLM Configuration
        • Chat Memory
        • Tools
        • Data Output
        • Agent Outcomes
      • AI Agent Proxy
        • AI Agents Integration
      • User Proxy Agent
      • xChatBot Integration
  • Examples
    • Basic Examples
    • Advanced Examples
      • Loan Approval Workflow
      • QMS AP Workflow
  • Administration
    • Monitoring and Logging
    • Security
    • Performance Tuning
  • Extensions and Customizations
    • Plugins and Add-ons
  • Troubleshooting
    • Common Issues
    • FAQs
  • Release Notes
    • Version History
    • Upcoming Features
  • Support
    • Contact Information
    • Community
Powered by GitBook
On this page
  1. Developer Guide
  2. Workflow States Reference

Switch State

Parameter
Description
Type
Required

name

Unique State name. Must follow the Serverless Workflow Naming Convention

string

yes

type

State type

string

yes

dataConditions

Defined if the Switch state evaluates conditions and transitions based on state data.

array

yes (if eventConditions is not defined)

eventConditions

Defined if the Switch state evaluates conditions and transitions based on arrival of events.

array

yes (if dataConditions is not defined

stateDataFilter

State data filter

object

no

onErrors

States error handling and retries definitions

array

no

timeouts

State specific timeout settings

object

no

defaultCondition

Default transition of the workflow if there is no matching data conditions or event timeout is reached. Can be a transition or end definition

object

yes

compensatedBy

Unique name of a workflow state which is responsible for compensation of this state

string

no

usedForCompensation

If true, this state is used to compensate another state. Default is false

boolean

no

metadata

Metadata information

object

no

Example:

JSON
YAML

Switch states can be viewed as workflow gateways: they can direct transitions of a workflow based on certain conditions. There are two types of conditions for switch states:

  • Data-based conditions

  • Event-based conditions

These are exclusive, meaning that a switch state can define one or the other condition type, but not both.

At times multiple defined conditions can be evaluated to true by runtime implementations. Conditions defined first take precedence over conditions defined later. This is backed by the fact that arrays/sequences are ordered in both JSON and YAML. For example, let's say there are two true conditions: A and B, defined in that order. Because A was defined first, its transition will be executed, not B's.

In case of data-based conditions definition, switch state controls workflow transitions based on the states data. If no defined conditions can be matched, the state transitions is taken based on the defaultCondition property. This property can be either a transition to another workflow state, or an end definition meaning a workflow end.

For event-based conditions, a switch state acts as a workflow wait state. It halts workflow execution until one of the referenced events arrive, then making a transition depending on that event definition. If events defined in event-based conditions do not arrive before the states eventTimeout property expires, state transitions are based on the defined defaultCondition property.

The timeouts property can be used to define state specific timeout settings. Switch states can define the stateExecTimeout setting. If eventConditions is defined, the switch state can also define the eventTimeout property. For more information on workflow timeouts reference the Workflow Timeouts section.

PreviousOperation StateNextParallel State

Last updated 1 year ago

{
     "name":"check-visa-status",
     "type":"switch",
     "eventConditions": [
        {
          "eventRef": "visa-approved-event",
          "transition": "handle-approved-visa"
        },
        {
          "eventRef": "visa-rejected-event",
          "transition": "handle-rejected-visa"
        }
     ],
     "timeouts": {
       "eventTimeout": "PT1H"
     },
     "defaultCondition": {
        "transition": "handle-no-visa-decision"
     }
}
name: check-visa-status
type: switch
eventConditions:
- eventRef: visa-approved-event
  transition: handle-approved-visa
- eventRef: visa-rejected-event
  transition: handle-rejected-visa
timeouts:
  eventTimeout: PT1H
defaultCondition:
  transition: handle-no-visa-decision