Switch Block
Last updated
Last updated
Nected's Switch Block is a control node available exclusively in the workflow editor. It allows users to define multiple execution paths based on specific conditions, thereby providing flexibility and precision in workflow management. This document provides a comprehensive guide on how to add and configure the Switch Block in your workflows.
In traditional workflow setups, multiple conditions need to be evaluated and acted upon independently.
The Switch Block introduces conditional flow just like the Switch case inside workflows, which helps address the inefficiencies of sequential flow. Here’s how the Switch Block solves these problems:
Conditional Execution: By defining multiple paths based on conditions, the Switch Block allows different parts of the workflow to run simultaneously. This reduces waiting time and increases overall efficiency.
Simplified Workflow Management: Conditions and actions are separated into different paths, making the workflow easier to understand, maintain, and debug.
With conditional execution, flows are utilized more effectively, as independent tasks can be processed concurrently.
To effectively utilize the Switch Block in your workflow, you'll need to follow a few straightforward steps. The process is intuitive, ensuring that you can quickly set up and manage complex workflows with conditional execution paths like switch-case, enhancing both flexibility and efficiency. Below, you'll find detailed instructions on how to add and configure the Switch Block within your workflow.
To add a Switch Block to your workflow, follow these steps:
Navigate to the Workflow Screen: Go to the workflow page where your workflows are listed.
Select a Workflow: Click on the workflow you wish to edit. This will open the workflow editor.
Add Switch Block: In the workflow editor, locate the option to add a new block. Select the Switch Block from the list of available blocks.
And you’re done. Now, the switch block will help you to make multiple condition-based outcomes in your workflow.
Once the Switch Block is added to your workflow, you need to configure it by defining conditions and corresponding actions. Here’s how to do it:
In the Switch Block configuration panel, go to the “Input Params” tab.
Before specifying the conditions specify the paths of execution like this:
Define Paths:
Each path represents a different case in the switch-case statement.
Unique Path Names: Ensure that each path within the same Switch Block has a unique name. However, paths in different Switch Blocks can have the same name, even if nested within each other.
To change the sequence of a PATH, just click on the button. And can figure out, the execution path of the function
Default Path: In the same Input Params tab, you can see the Default option at the bottom. The purpose of the default is the same as we see in the switch case. It will execute the default path if all conditions in other paths are not satisfied.
It is optional. You can define a default path that will be executed if none of the specified conditions are met. And if the option is off, there will be no default path for the case, if no other conditions are met. This ensures that the workflow always has a defined behavior and doesn’t break its flow. If the default option is turned off then the switch block will return the response only if no conditions are met.
Once the path is created, you can now set up the conditions that will determine the execution path. Conditions can be defined based on various parameters, such as data values, states, or external inputs, including fields like action.action
, additionalOutput
, and output
. While adding conditions, you have the flexibility to use logical operators such as "And" and "Or" to combine multiple conditions, just as in rule creation. By default, the operator is set to "And," but you can easily switch between "And" and "Or" by selecting the dropdown arrow button.
To further refine your conditions, you can create nested groups to add multiple constraints. Click the "+Add Group" button to create a new group within the existing conditions, or use the "+Convert to group" option to convert a single condition into a grouped set. This grouping and ungrouping feature allows you to organize complex logic structures effectively, providing better control over your execution path.
Whether you're creating nested conditions or not, you can create up to 10 paths only.
After configuring your Switch Block in the Input Params tab, click on the “Test” button below the panel, and the Test result tab will open to test your configured switch block.
In the Settings tab, there is an option to set the “timeout after” to simply set the timeout time of the switch block.
To set Actions, close the configuration panel first, and come back to the editor.
For each path that you’ve created, click on the + button to add the actions to be taken if the condition is met.
As Actions, you can again add any node including another Switch Block.
You have the option to delete a switch block with flexible choices to retain or remove specific branches as needed. When you click on the delete option for a switch block, a confirmation modal appears, providing the following options:
Delete the Complete Switch Block (Delete All Branches):
This option allows you to delete the entire switch block, including all its branches. Selecting this will remove the switch block and all the associated paths, including the default and custom branches, from the workflow.
Steps:
Click on the delete icon for the switch block.
In the modal, select the option to "Delete all branches."
Confirm your choice to delete the entire switch block.
Keep the Default Branch and Delete All Other Branches:
With this option, you can delete all branches except the default branch. This is useful if you want to simplify the switch case by retaining only the default path while removing other conditions.
Steps:
Click on the delete icon for the switch block.
In the modal, select "Keep the default branch and delete all other branches."
Confirm your selection to retain only the default branch.
Keep a Specific Branch and Delete All Other Branches (Except the Default Branch):
This option lets you choose a particular branch to keep while deleting all other branches, except the default branch. It’s ideal for cases where you need to preserve a specific path condition along with the default path.
Steps:
Click on the delete icon for the switch block.
In the modal, select "Keep a specific branch and delete all other branches."
Choose the specific branch you want to retain from the list of branches provided.
Confirm to delete all other branches except the selected branch and the default branch.
By using these options, you can quickly manage and modify switch cases within your workflow, keeping only the paths that are relevant to your current logic structure. This flexibility enhances the organization and simplicity of complex workflows.
Now, here is the troubleshooting guide, in case you missed anything
Condition Not Met:
Issue: The expected path is not being executed.
Solution: Double-check the condition definitions in the Switch Block configuration panel. Ensure that the parameters and values are correctly specified.
Default Path Not Executed:
Issue: The default path is not being triggered when conditions are not met.
Solution: Verify that the default path toggle is enabled in the Switch Block configuration panel.
Configuration Not Saved:
Issue: Changes made to the Switch Block configuration are not being saved.
Solution: After configuring the conditions and actions, ensure you click the "Save" button in the configuration panel.
Unexpected Behavior:
Issue: The workflow behaves unexpectedly after adding the Switch Block.
Solution: Review the entire workflow to ensure that the Switch Block and all other blocks are correctly configured and connected.
The Switch Block is useful when you want to execute only one rule based on specific conditions. Unlike a RuleSet, which allows rules to run in parallel, the Switch Block ensures that only one rule is triggered depending on the input or condition that is met.
To use the Switch Block to run one rule at a time, follow these steps:
Add a Switch Block Node:
In the Workflow Editor, drag and drop a Switch Block Node into your workflow.
Define the Conditions:
Open the Switch Block Node and define the conditions for each branch. Each condition will be evaluated, and only the rule corresponding to the matching condition will be executed.
Connect Rules to the Switch Block:
Connect multiple rules to the Switch Block. For each branch (condition), connect one rule. Only the rule that matches the evaluated condition will be executed, ensuring that no two rules run simultaneously.
Test the Workflow:
Before deployment, thoroughly test the workflow with various inputs to ensure that the correct rule is executed based on the conditions.
To run rules in parallel, try using a ruleset using a rule node.
The Switch Block feature in Nected provides a versatile way to control the flow of workflows based on specified conditions. By following this guide, you can effectively implement and utilize Switch Blocks to enhance your workflow management processes, ensuring flexibility and precision.
By referring to the attached images and following the troubleshooting guide, you can resolve common issues and ensure the smooth operation of your workflows with Switch Blocks.