Code
The Code piece in ZBrain Flow provides powerful scripting capabilities that allow you to execute custom code within your workflows. This component enables advanced data manipulation, complex calculations, custom algorithms, and more services that may not be covered by standard components. With the Code piece, you can write custom logic in either JavaScript/TypeScript or Python, depending on your preference and requirements.
How to Use the Code Piece in ZBrain Flow?
Step 1: Select Code as Your Connection
Click on the '+' button in the Flow and search for Code.
Select Code.
Decide on the action you need. ZBrain Flow provides two options:
Custom JavaScript Code: For Node.js & TypeScript code with npm support
Custom Python Code: For Python scripts and libraries
How to Write Custom JavaScript Code?
Step 1: Set Up Your Inputs
To pass data from previous steps into your code:
In the ‘Inputs’ section, click ‘Add Item’ for each piece of data you want to access.
For each input, specify:
A name for the input (this becomes the key to access it in your code)
The value from previous steps you want to pass in
In your code, access these inputs using
inputs.key
syntax (where "key" is the name you assigned)
Step 2: Write Your JavaScript/TypeScript Code
In the Code editor, write the standard JavaScript/Node.js syntax for your logic.
Step 3: Add Dependencies (If Needed)
If your code requires npm packages:
Click ‘Add package.’
Specify the package name you need, and the latest version will be fetched.
Click the ‘Add’ button.
How to Write Custom Python Code?
Once you select Custom Python Code as your action, follow the same approach as described in the JavaScript implementation for setting up inputs, writing your code, and configuring error handling options (Steps 1, 2 and 4). If you want to add Python packages, follow the below steps:
Click ‘Add packages.’
Select a requirement file from your device and press the ‘Add’ button.
Last updated