> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Wizard Branching Guide

> This guide explains how to create dynamic, conditional workflows using branching logic in configurable wizards.

This guide explains how to create dynamic, conditional workflows using branching logic in configurable wizards.

## Overview

Branching allows wizards to take different paths based on user input. For example:

* Skip benefits selection for part-time employees
* Show additional questions for international applicants
* Route to different review steps based on request type

## Creating a Branch Step

1. In the Wizard Builder, click **Add Step**
2. Select **Branch** as the step type
3. Configure the branching conditions

## Anatomy of a Branch

A branch step consists of:

| Component          | Description                             |
| ------------------ | --------------------------------------- |
| **Conditions**     | Rules that determine which path to take |
| **Target Steps**   | Where each condition leads              |
| **Default Target** | Fallback if no conditions match         |

## Configuring Conditions

Each condition has three parts:

1. **Field** - The form field to evaluate
2. **Operator** - The comparison type
3. **Value** - What to compare against (if applicable)

### Available Operators

| Operator           | Description             | Example                         |
| ------------------ | ----------------------- | ------------------------------- |
| `equals`           | Exact match             | employment\_type = "full\_time" |
| `not_equals`       | Not an exact match      | status ≠ "inactive"             |
| `contains`         | Text contains substring | notes contains "urgent"         |
| `not_contains`     | Text doesn't contain    | name not contains "test"        |
| `starts_with`      | Text prefix match       | email starts\_with "admin"      |
| `ends_with`        | Text suffix match       | email ends\_with "@company.com" |
| `greater_than`     | Numeric comparison      | age > 18                        |
| `greater_or_equal` | Numeric comparison      | salary ≥ 50000                  |
| `less_than`        | Numeric comparison      | years \< 5                      |
| `less_or_equal`    | Numeric comparison      | score ≤ 100                     |
| `is_empty`         | Field has no value      | notes is empty                  |
| `is_not_empty`     | Field has a value       | phone is not empty              |
| `in_list`          | Value is one of several | status in \[active, pending]    |
| `not_in_list`      | Value is not in list    | type not in \[test, demo]       |
| `matches_regex`    | Pattern matching        | phone matches \d{3}-\d{4}       |

### Operator Availability by Field Type

| Field Type         | Available Operators                                                   |
| ------------------ | --------------------------------------------------------------------- |
| Text, Email, Phone | equals, contains, starts\_with, ends\_with, matches\_regex, is\_empty |
| Number, Currency   | equals, greater\_than, less\_than, is\_empty                          |
| Date, DateTime     | equals, greater\_than, less\_than, is\_empty                          |
| Select, Picklist   | equals, in\_list, not\_in\_list, is\_empty                            |
| Multiselect        | contains, is\_empty                                                   |
| Checkbox           | equals, is\_empty                                                     |

## Multiple Conditions

You can add multiple conditions to a single branch step:

1. Click **Add Condition**
2. Configure each condition
3. Conditions are evaluated **in order**
4. The **first matching condition** determines the path

```
Condition 1: IF employment_type = "full_time" → Benefits Step
Condition 2: IF employment_type = "part_time" → Summary Step
Default: → Exit Interview Step
```

## Setting the Default Target

The default target is required and handles cases where no conditions match:

1. Select a step from the **Default Target** dropdown
2. This is the "fallback" path
3. Always test your default path

## Validation & Warnings

The Wizard Builder validates your branches:

### Errors (Must Fix)

* ❌ **Missing default target** - Every branch needs a fallback
* ❌ **Non-existent target** - Target step doesn't exist
* ❌ **Self-referencing** - Branch points to itself (infinite loop)
* ❌ **Cycle detected** - A → B → A (infinite loop)

### Warnings

* ⚠️ **Unreachable step** - A step that no path leads to
* ⚠️ **Missing field** - Condition references field not in previous steps

## Branch Execution

When a user reaches a branch step:

1. Conditions are evaluated in order
2. First matching condition's target is used
3. If no match, default target is used
4. User is automatically navigated to the target step

> **Note:** Branch steps are invisible to users—they're evaluated instantly.

## Best Practices

### Keep It Simple

* Limit branching depth to 2-3 levels
* Use clear, descriptive step names
* Document complex logic in step descriptions

### Test All Paths

Before publishing:

1. Use the Preview mode with test data
2. Walk through each possible path
3. Verify the review step shows correct data

### Handle Edge Cases

* Always set a sensible default
* Consider what happens with empty values
* Test with unexpected inputs

## Example: Employee Onboarding

```
Step 1: Personal Information
  - First Name, Last Name, Email

Step 2: Employment Type
  - Type: [Full-time, Part-time, Contractor]

Step 3: Employment Branch
  - IF type = "full_time" → Benefits Step
  - IF type = "part_time" → Equipment Step
  - DEFAULT → Contractor Agreement Step

Step 4a: Benefits Selection (full-time only)
  - Health plan, 401k, PTO

Step 4b: Equipment Request (part-time only)
  - Laptop, Badge access

Step 4c: Contractor Agreement
  - Contract terms

Step 5: Review & Submit
```

## Troubleshooting

### Branch Not Working as Expected

1. Check condition order (first match wins)
2. Verify field names match exactly
3. Check for typos in comparison values
4. Use the Path Validator tool

### Unreachable Step Warning

This means a step exists but no path leads to it:

1. Add a condition that targets the step
2. Set it as the default target
3. Or remove the orphaned step

### Cycle Detected Error

You have a loop in your branching:

1. Review all branch configurations
2. Ensure no step eventually leads back to itself
3. Use the visual path diagram to trace routes

## Related Documentation

* [Wizard Analytics Guide](./wizard-analytics-guide.md)
* [Wizard AI Generation Guide](./wizard-ai-generation-guide.md)
* [Wizard Builder Documentation](../../src/platform/wizards/README.md)
