Code Snippets
Overview
Like many low-code/no-code platforms, UPTIQ allows developers to inject custom code into workflows when required. The Workbench provides the ability to execute JavaScript code using Code Snippets, which can be embedded in workflows through the "Javascript" Node.
What is a code snippet?
A Code Snippet is a simple JavaScript function named main
, which:
Takes input from the previous node in the workflow.
Stores that input in a special variable
input
, making it available throughout the function.Outputs the processed result, which becomes the input for the next node in the workflow.
Understanding 'Input' in Code Snippets
Since every node’s output becomes the input for the next node, the data type of the input
variable depends on the preceding node’s output:
If the previous node outputs a JSON object,
input
will be of type JSON.If the previous node outputs a string or number,
input
will hold that respective type.
This flexibility allows developers to manipulate, transform, or filter data dynamically within workflows.
When to Use Code Snippets?
Developers can use JavaScript Nodes for: ✅ Data Formatting & Transformation – Convert data formats, adjust values, or prepare data for API calls. ✅ Basic Filtering – Remove unnecessary fields or extract key data before passing it to the next node. ✅ Applying Business Logic – Execute programmatic operations that aren’t natively supported by other workflow nodes. ✅ Custom Computations – Perform calculations or data aggregations before the AI agent processes the result.
Best Practices & Pitfalls of Using JavaScript Nodes
🚨 Avoid Overuse of JavaScript Nodes While JavaScript nodes add flexibility, excessive use can:
Reduce Workflow Readability – Business logic may become hidden inside code, making workflows harder to understand.
Complicate Debugging & Maintenance – Unlike visual nodes, JavaScript logic isn’t easily visible, which can make troubleshooting time-consuming.
Break the Low-Code Advantage – Workflows should remain as low-code as possible; use JavaScript only when absolutely necessary.
💡 Recommendation: Use JavaScript Nodes sparingly. Always check if the same transformation or filtering can be achieved with other workflow nodes before resorting to custom code.
How to create a code snippet?
There are two ways to create a Code Snippet:
1. From Config & Utils
Navigate to Config & Utils → Code Snippet Tab.
Click "Create Code Snippet."
Enter a meaningful name for easy identification in workflows.
Select the agent where the code snippet will be used.
Click Save—the snippet is now available for workflows.
2. Directly from a JavaScript Node (Quick Method)
Drag a JavaScript Node into the workflow.
Click on the node to open the side panel.
Click "Add Script"—this creates a new snippet and automatically assigns it to the agent.
Save the snippet and later update it with the required business logic.
Key Takeaways for Developers
✅ Leverage JavaScript Nodes for targeted logic execution, such as data transformations and filtering. ✅ Ensure workflow readability by limiting JavaScript usage to essential cases. ✅ Use reusable Code Snippets to maintain modularity and avoid redundant script writing. ✅ Prioritize low-code workflow nodes whenever possible for better maintainability and collaboration.
By using Code Snippets effectively, developers can enhance workflow capabilities without compromising the benefits of low-code/no-code development in UPTIQ.
Last updated