Code
A guide on how to use the Code Action to execute custom Python or JavaScript for advanced data manipulation and logic.
The Code Action is a powerful feature for advanced users that allows you to run custom Python or JavaScript code within your workflow. This unlocks a new level of flexibility, enabling you to perform complex data transformations, implement custom logic, or interact with libraries that aren't available through standard actions.
Configuration
The action is configured with the code you want to execute and any input data it needs.
Input Parameters
Language
Dropdown
The programming language to use: Python
or JavaScript
.
Inputs
Key-Value
A set of key-value pairs that will be passed into your code as a dictionary or object named inputs
. This is how you access data from previous actions.
Code
Code Editor
The block of code to be executed.
Accessing Inputs
Data from the Inputs
configuration is available within your script:
In Python, it's a dictionary called
inputs
. You can access values withinputs['key_name']
.In JavaScript, it's an object called
inputs
. You can access values withinputs.key_name
.
Returning Data
To pass data to downstream actions, your script must return a dictionary (Python) or an object (JavaScript). The keys and values of this returned object will become the outputs of the Code Action.
Example: Simple Data Transformation (Python)
Let's say a previous action gives you a user's full name, and you want to extract the first name.
Inputs Configuration:
Key:
full_name
Value:
{{previous_action.user_name}}
(e.g., "John Doe")
Code (Python):
Output
The output of the action is determined entirely by the object or dictionary your code returns.
Example Output
Based on the example above, the Code Action would have one output variable, first_name
, which could be accessed in a subsequent action as {{code_action.first_name}}
. Its value would be John
.
Last updated
Was this helpful?