Introduction
The Function Node in Canonic workflows enables you to write custom JavaScript functions, offering extensive flexibility and control within your workflows. It is equipped with a code editor that allows for intricate logic and data manipulation.
Features
- Custom Code Execution: Write and execute your own JavaScript functions.
- Access to Workflow Data: Easily interact with data from other nodes in the workflow.
- Asynchronous Operations: Support for asynchronous JavaScript, allowing for operations like API calls or database queries.
Accessing Data
In the Function Node's code editor, you can access the workflow's parameters:
module.exports = function (params) {
// Accessing input data
const inputData = params.input
// Accessing data from previous nodes
const previousData = params["NODE_INDEX"].output // Replace 'NODE_INDEX' with the index of the desired node
// ... your custom logic ...
}
Writing Custom Functions
- Navigate to your Function Node in the workflow.
- Open the Code Editor to start writing your JavaScript function.
- Implement your logic using the available data and JavaScript capabilities.
Testing and Debugging
- Test Thoroughly: After writing your function, use Canonic's built-in testing tools to ensure correct operation.
- Debugging: Implement console logging and error handling for debugging purposes.
Best Practices
- Robust Error Handling: Ensure that your code gracefully handles errors and edge cases.
- Optimized Code: Write efficient code to maintain performance, especially for complex logic or data-heavy operations.
- Commenting and Documentation: Keep your code well-commented for easier maintenance and understanding.
Note: The Function Node provides a powerful way to introduce custom behavior and logic into your Canonic workflows. Ensure your functions are well-tested, efficient, and maintain the overall integrity of the workflow.