Custom Code Node
Last updated
Last updated
In the Code Node, users can execute custom javascript code within the workflow. This provides flexibility to perform complex computations, data manipulations, or integrate custom logic.
Find the spot in your workflow where you need the custom code execution to occur.
Choose the Code Node from the 'Add Node' panel and place it on the workflow canvas.
This is where you specify any input parameters your code needs.
Select Language:
Choose the scripting or programming language you will use. In the screenshot, JavaScript is selected, which is commonly supported in workflow tools.
Add Query/Code:
Write or paste your code in the provided code editor. You can incorporate workflow data using tokens, such as {{Trigger.item_no[0]}}
, which would access data from the workflow trigger.
After coding, you can test the script to ensure it executes as expected within the workflow context.
Testing the Code:
Provide necessary inputs if your code requires them, and click the 'Test' button. This will execute the script within a controlled environment and return the results.
Interpreting the Output:
The output from the execution of your code will be displayed in JSON format, allowing you to validate the results of your script.
Adjust the execution settings for your code within the workflow.
The "Timeout after" option allows you to set a time limit for the node's operation. If the node takes longer than the specified time, it will automatically stop running.
If you turn this setting on, then even if the workflow node gets any error, the workflow will continue to execute the next node with the error.
Let's take an example:
Let's say we have these 3 nodes in our workflow:
The first one is a Formula node, the second one is a Rule node and the third one is a database node.
In the past, our workflow system was designed with a stringent error management approach. If any node within the workflow encountered an error at any point during its execution, the entire process would come to a complete halt. This meant that if the first node, for example, "modified_cart," experienced any error, the workflow would not proceed to the next node. Instead, it would stop immediately at the first node, requiring immediate intervention to address the error before the workflow could continue. This approach prioritized error verification and strict control over processes, but it also meant increased interruptions and potential delays as errors were resolved one at a time.
Our current system introduces a feature called "Continue on error," which can be toggled on or off for each node in the workflow. When this setting is activated, it allows the workflow to proceed to the next node even if an error occurs in the current node. Specifically, if the first node, like "modified_cart," encounters an error while this setting is enabled, the workflow will not be halted. Instead, it will advance to the subsequent node, such as the rule node, with the error details passed along from the previous node. This functionality facilitates the continuation of the workflow despite errors, promoting greater flexibility and resilience in managing workflows by allowing for potential error handling at later stages of the process.