Using transform-data steps
Using transform-data steps
Use a transform-data step to run code that formats, filters, combines, or calculates Flow data. The Flow editor labels this step Run Code.
Before you begin
Open a Flow in the Flow editor. For instructions, see Creating and editing flows.
Add a transform-data step
To add and configure a transform-data step, follow these steps:
- In the Flow editor, click the + control where you want to insert the step.
- In the step picker, select Run Code. The step card opens.
- In Execution environment, choose the environment that matches your code. The default Cloudflare Worker (Default) environment runs JavaScript.
- In Input mode, select Code (Write your own logic).
- Select a code template or click Write code to open the editor.
- In the code editor, write a script that returns the value that you want to store.
- In Output variable, enter the name for the returned value.
- In the toolbar, click Create for a new Flow or Save for an existing Flow.
Optional: Rename the step in its header to describe its transformation.
Choose an execution environment
The Flow editor provides these execution environments:
- Cloudflare Worker (Default): Runs JavaScript with
async/await, exposes built-in helpers underhelpers.*, and blocks network access by default. - Runtype Sandbox: Runs JavaScript, TypeScript, and Python in a container. It supports package installation and sandbox persistence.
- Daytona Sandbox: Runs JavaScript, TypeScript, and Python in a container. It supports package installation and sandbox persistence.
- QuickJS (Legacy): Runs JavaScript synchronously and exposes built-in helpers as global functions.
To run TypeScript or Python, choose Runtype Sandbox or Daytona Sandbox, then set Language to the language that you want to use.
To install packages in a container environment, enter the package metadata in Package.json (Optional). For HTTP requests that need step-level request and response configuration, use the fetch-url and api-call steps.
Write a script
Write JavaScript that returns a value. The runtime makes earlier step outputs available by their outputVariable names. Valid, non-reserved JavaScript variable names are available at the top level, and the complete variable map is available through input.
Use the following script to format a customer object:
Replace customer_data with the earlier step’s outputVariable name.
Reference output from an earlier step by its outputVariable name. The following script counts words in a generated summary:
Replace generate_summary with the earlier step’s outputVariable name.
Common transformations
Use the following patterns to transform arrays, objects, strings, and numbers.
Filter and map arrays
Filter an array and create a new object for each remaining item:
Replace order_data with the variable that contains the order list.
Merge objects
Combine values from multiple sources into one object:
Replace customer_data and order_history with the variables that you want to merge.
Format strings
Create a name and a URL-friendly slug from contact information:
Replace contact_info with the variable that contains the contact information.
Calculate values
Calculate a cart subtotal, tax, and total:
Replace cart with the variable that contains the cart items.
Use available JavaScript features
JavaScript transform scripts support these features:
- Array methods such as
map,filter, andreduce. - Destructuring and spread operators.
- Arrow functions.
- Template literals.
async/awaitin environments that support asynchronous execution.Dateobjects.Mathfunctions.JSON.parseandJSON.stringify.- Built-in helper functions in environments that provide them.
External libraries are unavailable in Cloudflare Worker (Default) and QuickJS (Legacy). Choose Runtype Sandbox or Daytona Sandbox when your script needs packages.
Handle errors
Transform-data steps continue after a script error by default. The step stores its configured default value in the output variable, or null when no default exists, and records the error on the step result. To stop the Flow, choose Stop on error in the step’s error-handling control.
Wrap operations that can throw in try/catch when you want to return a structured result:
Replace raw_data with the variable that contains the JSON string. Use a downstream Conditional Logic step to branch on success.
Test a transformation
To test a top-level transform-data step against variables from the last run, follow these steps after the Flow has run once:
- Run the Flow once.
- On the top-level step card, click the action menu (⋯).
- Choose Test with last run. The test sheet opens.
- Review the output and update the script if needed.
Follow best practices
Use these practices when you write transform-data scripts:
- Keep each transformation focused.
- Name each step and output variable to describe its result.
- Check for
nullandundefinedbefore you access properties. - Return the same structure from each successful run.
Next steps
Continue with these guides:
- Flow variables and templates: reference inputs and step outputs.
- Using conditional steps: branch on transformed values.
- Using fetch-url and api-call steps: fetch data before you transform it.