> ## 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.

# Workflow Examples

> This document provides real-world examples of workflows you can build with the Encore OS Visual Workflow Builder.

This document provides real-world examples of workflows you can build with the Encore OS Visual Workflow Builder.

***

## Example 1: Simple Notification Workflow

**Use Case:** Send email notification when form is submitted.

**Workflow:**

```
[Start] → [Send Email] → [Send In-App Notification] → [End]
```

**Configuration:**

1. **Start Node:** No configuration needed

2. **Send Email Action:**
   * Action Type: `send_email`
   * To: `{{submission_data.email}}`
   * Subject: `Your submission was received`
   * Body: `Thank you for submitting the form. We'll review your information and get back to you soon.`

3. **Send Notification Action:**
   * Action Type: `send_notification`
   * User ID: `{{submitted_by}}`
   * Type: `form_submitted`
   * Title: `Form Submitted Successfully`
   * Body: `Your form has been submitted and is under review.`

4. **End Node:** No configuration needed

***

## Example 2: Approval Workflow

**Use Case:** Manager must approve expense reports before processing.

**Workflow:**

```
[Start] → [Approval] → {Approved → [Update Record] → [Notify Employee] → [End]}
                    └→ {Rejected → [Notify Employee] → [End]}
```

**Configuration:**

1. **Approval Node:**
   * Assignee Role: `org_admin`
   * Instructions: `Please review this expense report`
   * Timeout: 48 hours (auto-reject)

2. **Update Record (Approved Path):**
   * Action Type: `update_record`
   * Table: `expense_reports`
   * Record ID: `{{submission_id}}`
   * Updates: `{"status": "approved", "approved_at": "{{now}}"}`

3. **Notify Employee (Both Paths):**
   * Action Type: `send_notification`
   * User ID: `{{submitted_by}}`
   * Title: `Expense Report Decision`
   * Body: Conditional based on path

***

## Example 3: Branching Workflow

**Use Case:** Route high-value purchases to executive approval, low-value purchases auto-approve.

**Workflow:**

```
[Start] → [Branch] → {amount > 1000 → [Executive Approval] → [Process Order] → [End]}
                  └→ {else → [Auto-Approve] → [Process Order] → [End]}
```

**Configuration:**

1. **Branch Node:**
   * Condition 1:
     * Field: `submission_data.amount`
     * Operator: `greater_than`
     * Value: `1000`
   * Default: Auto-approve path

2. **Executive Approval:**
   * Assignee Role: `org_admin`
   * Instructions: `High-value purchase requires approval`

3. **Auto-Approve:**
   * Action Type: `update_record`
   * Updates: `{"status": "approved", "auto_approved": true}`

4. **Process Order:**
   * Action Type: `call_webhook`
   * URL: `https://api.example.com/orders`
   * Method: `POST`
   * Body: `{{submission_data}}`

***

## Example 4: Loop Workflow

**Use Case:** Send individual emails to each recipient in a list.

**Workflow:**

```
[Start] → [Loop] → {body → [Send Email]} → {done → [End]}
```

**Configuration:**

1. **Loop Node:**
   * Loop Type: `for_each`
   * Collection Field: `submission_data.recipients`
   * Item Variable: `recipient`
   * Max Iterations: `100`

2. **Send Email (Loop Body):**
   * Action Type: `send_email`
   * To: `{{recipient.email}}`
   * Subject: `Invitation from {{submission_data.sender_name}}`
   * Body: `Hello {{recipient.name}}, you've been invited...`

***

## Example 5: Parallel Workflow

**Use Case:** Send email AND create task simultaneously for efficiency.

**Workflow:**

```
[Start] → [Parallel Fork] → {Branch 1 → [Send Email]}
                         └→ {Branch 2 → [Create Task]}
       → [Parallel Join] → [Update Status] → [End]
```

**Configuration:**

1. **Parallel Fork:**
   * Branches: 2

2. **Send Email (Branch 1):**
   * Action Type: `send_email`
   * To: `{{submission_data.assignee_email}}`
   * Subject: `New task assigned`

3. **Create Task (Branch 2):**
   * Action Type: `create_record`
   * Table: `tasks`
   * Data: `{"title": "{{submission_data.task_title}}", "assignee_id": "{{submission_data.assignee_id}}"}`

4. **Parallel Join:**
   * Join Mode: `all` (wait for both branches)

5. **Update Status:**
   * Action Type: `update_record`
   * Updates: `{"notification_sent": true, "task_created": true}`

***

## Example 6: Switch Workflow

**Use Case:** Route form to different departments based on category.

**Workflow:**

```
[Start] → [Switch] → {HR → [Notify HR Team] → [End]}
                  └→ {IT → [Notify IT Team] → [End]}
                  └→ {Finance → [Notify Finance Team] → [End]}
                  └→ {default → [Notify General] → [End]}
```

**Configuration:**

1. **Switch Node:**
   * Switch Field: `submission_data.department`
   * Cases:
     * `HR` → HR notification path
     * `IT` → IT notification path
     * `Finance` → Finance notification path
   * Default: General notifications

2. **Notify Team Nodes:**
   * Action Type: `send_notification`
   * User ID/Role: Department-specific
   * Title: `New request for {{submission_data.department}}`

***

## Example 7: Subflow Workflow

**Use Case:** Reuse employee onboarding checklist across multiple forms.

**Subflow: Employee Setup**

```
[Input: employee_id, start_date]
  → [Create HR Record]
  → [Assign Equipment]
  → [Schedule Training]
  → [Send Welcome Email]
[Output: success, employee_number]
```

**Parent Workflow:**

```
[Start] → [Validate Data] → [Call Subflow: Employee Setup] → [Update Form] → [End]
```

**Configuration:**

1. **Subflow Node:**
   * Subflow: `Employee Setup`
   * Input Mapping:
     * `employee_id` ← `submission_data.employee_id`
     * `start_date` ← `submission_data.start_date`
   * Output Mapping:
     * `submission_data.employee_number` ← `employee_number`
     * `submission_data.setup_complete` ← `success`

***

## Example 8: Complex Multi-Stage Workflow

**Use Case:** Comprehensive leave request approval with multiple approvers and notifications.

**Workflow:**

```
[Start]
  → [Validate Hours]
  → [Branch: Leave Type]
      {Medical → [Manager Approval] → [HR Approval] → [Update Balance] → [Notify Employee] → [End]}
      {Vacation → [Manager Approval] → [Update Balance] → [Notify Employee] → [End]}
      {Emergency → [Auto-Approve] → [Notify Manager] → [Update Balance] → [Notify Employee] → [End]}
```

**Configuration:**

1. **Validate Hours:**
   * Action Type: `run_function`
   * Function: Check available balance

2. **Branch: Leave Type:**
   * Conditions for medical, vacation, emergency

3. **Manager Approval:**
   * Assignee: `{{submission_data.manager_id}}`
   * Timeout: 24 hours

4. **HR Approval:**
   * Assignee Role: `org_admin`
   * Instructions: `Review medical leave request`

5. **Update Balance:**
   * Action Type: `update_record`
   * Table: `leave_balances`
   * Deduct hours from balance

6. **Notifications:**
   * Send to employee with approval status
   * CC manager for visibility

***

## Tips for Building Complex Workflows

1. **Start Small:** Build incrementally, test each section
2. **Use Subflows:** Extract common patterns (notifications, approvals)
3. **Add Labels:** Name nodes clearly for readability
4. **Default Paths:** Always handle "else" cases in branches
5. **Error Handling:** Use branch nodes to check for errors
6. **Test Thoroughly:** Use dry-run mode before production
7. **Document:** Add descriptions to complex nodes

***

## Common Patterns

### Pattern: Notify Multiple People

```
[Start] → [Parallel Fork] → {Notify Manager}
                         └→ {Notify HR}
                         └→ {Notify Employee}
       → [Parallel Join] → [End]
```

### Pattern: Retry Failed Action

```
[Start] → [Loop While: retry_count < 3]
            → [Try Action]
            → [Branch: Success?]
                {Yes → Break Loop}
                {No → Increment retry_count}
         → [Done] → [End]
```

### Pattern: Conditional Approval

```
[Start] → [Branch: Amount > $5000]
            {Yes → [CFO Approval]}
            {No → [Manager Approval]}
         → [Process Payment] → [End]
```

***

## Need More Examples?

Visit the workflow template library in Encore OS or contact support for custom workflow design assistance.
