Conditional Operations
Conditional operations enable branching and decision-making in workflows, allowing different execution paths based on evaluated conditions. These operations are essential for building intelligent workflows that adapt their behavior based on data, results from previous operations, or workflow parameters.
Overview
Raikoo provides three conditional operations for controlling workflow execution:
- If-Then — Executes child operations only when a condition is true
- If-Then-Else — Executes one set of child operations when true, another when false
- Switch — Routes execution to one of multiple named paths based on an expression's value
All three operations evaluate JavaScript expressions that can reference operation results and workflow parameters using text replacement syntax (e.g., {{OperationName.Result}} or {{Workflow.Parameters.paramName}}). This allows you to make decisions based on dynamic data flowing through your workflow.
If-Then
The simplest conditional operation. Evaluates a JavaScript expression and executes child operations only if the result is truthy.
Configuration
- Expression (required): JavaScript expression to evaluate. Must return a truthy or falsy value.
How It Works
- The expression is evaluated
- If the result is truthy (true, non-zero number, non-empty string, object, array, etc.), child operations execute in sequence
- If falsy (false, 0, null, undefined, empty string, NaN), child operations are skipped entirely
- Execution continues with the next operation after the If-Then block
Example Expressions
{{PreviousOp.Result}} === "approved"
{{Workflow.Parameters.count}} > 10
{{DataCheck.Output}}.includes("valid")
{{APIResponse.statusCode}} === 200
{{UserProfile.isActive}} && {{UserProfile.emailVerified}}
If-Then-Else
Extends If-Then with an alternative execution path for when the condition is false. This ensures that one of two possible branches always executes.
Configuration
- Expression (required): JavaScript expression to evaluate
How It Works
- The expression is evaluated
- If truthy, the "Then" branch child operations execute
- If falsy, the "Else" branch child operations execute
- Execution continues with the next operation after the If-Then-Else block
Only one branch executes per evaluation—never both.
Example Use Cases
- Processing documents differently based on file type: Route PDFs to OCR processing while sending images to visual analysis
- Routing customer requests based on priority level: Assign high-priority tickets to senior agents, standard tickets to the general queue
- Applying different transformations based on data validation results: Use validated data as-is or apply cleansing operations to invalid data
- Conditional notifications: Send alerts for error conditions, log success messages otherwise
Switch
The most flexible conditional operation. Evaluates a JavaScript expression and routes execution to a named path matching the result. This is ideal when you have multiple distinct execution paths to choose from.
Configuration
- Expression (required): A JavaScript expression that determines the execution path
- Boolean conditions return "true" or "false"
- Other expressions return their stringified value (e.g., "A", "B", "default")
- Paths: Configure named execution paths that match possible expression results
How It Works
- The expression is evaluated and converted to a string
- Execution routes to the path whose name matches the expression result
- If no matching path is found, no child operations execute (consider adding a "default" path)
- Each path can contain its own set of child operations
- Only the matched path executes
Boolean Mode
When the expression evaluates to a boolean, configure two paths:
- true: Operations to execute when the condition is true
- false: Operations to execute when the condition is false
This provides similar functionality to If-Then-Else but uses the Switch operation's path-based structure.
Multi-Path Mode
For expressions that return string or numeric values, create paths named after each expected value:
Expression: {{DocumentType.Result}}
Paths:
- "invoice" → Process as invoice (extract line items, calculate totals)
- "receipt" → Process as receipt (extract merchant, date, amount)
- "contract" → Process as contract (extract parties, terms, signatures)
- "default" → Handle unknown type (log warning, route to manual review)
Example Expressions
// Boolean evaluation
{{ValidationOp.Result}} === "pass"
{{Workflow.Parameters.enableFeature}} === true
// Multi-value string matching
{{ClassifyOp.Category}}
{{HTTPRequest.method}}
{{DataSource.region}}
// Computed values with ternary operators
{{ScoreOp.Value}} >= 90 ? "excellent" : {{ScoreOp.Value}} >= 70 ? "good" : "needs_review"
// Complex logic
{{Order.total}} > 1000 ? "premium" : {{Order.customerTier}}
Best Practices
- Use descriptive path names in Switch operations for readability and maintainability
- Always include a default path in Switch operations to handle unexpected values and prevent silent failures
- Keep expressions simple — complex logic should be handled in preceding operations that produce clear, simple values to evaluate
- Test conditions thoroughly — verify both true and false paths execute correctly, including edge cases
- Combine with iterators — conditional operations work inside iterator loops for filtering and conditional processing of collections
- Reference operation results using text replacements:
{{OperationName.ParameterName}}or{{OperationName.Result}} - Use meaningful operation names — clear names make expressions more readable (e.g.,
{{ValidateEmail.IsValid}}instead of{{Op1.Output}}) - Consider error handling — add conditionals to check for errors or null values before processing data
- Document complex conditions — use operation descriptions to explain the logic behind complex conditional expressions
Combining Conditions with Other Operations
Conditional operations are most powerful when combined with other operation types. Here are common patterns:
Iterator Operations
Use conditionals inside iterator loops to filter or process items selectively:
Iterator: Loop through {{GetOrders.Results}}
└─ If-Then: {{CurrentItem.status}} === "pending"
└─ ProcessOrder operation
└─ SendNotification operation
This pattern allows you to process only items that meet specific criteria without needing separate filtering operations.
System Operations
Route data to different system operations based on conditions:
Switch: {{FileUpload.fileType}}
Path "pdf":
└─ ExtractTextFromPDF operation
└─ SaveToDocumentStore operation
Path "csv":
└─ ParseCSV operation
└─ ImportToDatabase operation
Path "image":
└─ ImageAnalysis operation
└─ ExtractMetadata operation
Path "default":
└─ LogWarning operation
└─ NotifyAdmin operation
AI Operations
Make decisions based on AI classification or analysis results:
AIClassify: Analyze customer sentiment from {{CustomerFeedback.text}}
└─ Output: sentiment
Switch: {{AIClassify.sentiment}}
Path "positive":
└─ SendThankYou operation
└─ UpdateCRM operation
Path "negative":
└─ CreateSupportTicket operation
└─ NotifyManager operation
└─ ScheduleFollowUp operation
Path "neutral":
└─ AddToSurvey operation
Nested Conditions
Combine multiple conditional operations for complex decision trees:
If-Then: {{Order.value}} > 500
└─ If-Then-Else: {{Customer.isPremium}} === true
Then:
└─ ApplyPremiumDiscount operation
└─ ExpressShipping operation
Else:
└─ ApplyStandardDiscount operation
└─ StandardShipping operation
Keep nesting to a minimum for maintainability. Consider breaking complex logic into separate workflows or using Switch operations with computed paths.