A code step lets you run a small piece of custom logic directly inside an automation flow, alongside your actions, conditions, and model steps. It is a lightweight way to drop in tailored behavior exactly where you need it - you write, preview, and edit the code without leaving the builder, and a built-in AI assistant can generate the code for you, so you do not need coding experience to use one.
This guide explains when to reach for a code step, how to add one to a flow, and how to write, test, and configure it. For a refresher on flows themselves, see Create your first automation flow.
What is a code step?
A code step runs inline JavaScript as a single step in your flow. When the flow reaches the step, your code runs, receives the inputs available at that point in the flow, and returns a value that later steps can use.
Code steps run in a secure, sandboxed environment. You can keep the logic simple, or, for more advanced needs, add npm packages and build something more involved. Because the code lives inside the flow, you can iterate on it quickly and see at a glance what it does.
Code step or Custom Action?
Code steps and Custom Actions both let you add custom logic, but they suit different situations:
- Use a code step when the logic is only needed in a single automation. You keep it right where it is used and can edit it in place, without creating a separate, reusable building block.
- Use a Custom Action when you want logic that can be reused across many automations, with versioning and shared variables and secrets. See Build and use a Custom Action.
A good rule of thumb: start with a code step for one-off logic, and promote the logic to a Custom Action when you find yourself needing it in more than one flow.
Add a code step to a flow
In the automation builder:
- Open or create a flow as described in Create your first automation flow.
- Hover over the block you want the code step to run after, then click the + icon that appears.
- In the block picker, select the Code Step block.
The code step is added to your flow, ready for you to write its logic.
Write the code
Open the code step to edit it. You have two ways to write the logic.
Use the AI assistant
Describe what you want in plain language and the built-in assistant generates the code for you. This is the fastest way to get started and does not require any coding experience. Review the generated code, adjust your description if needed, and regenerate until it does what you want.
Write it yourself
For technical users, the editor is a full JavaScript environment with syntax highlighting and live error checking, so you can catch problems as you type. Your code receives the inputs available at that point in the flow and must return a value. Whatever you return becomes available to the steps that follow, so a code step can transform data, compute a value, or look something up and hand the result back to the rest of the flow.
Add packages
If your logic needs functionality beyond plain JavaScript, you can add npm packages as dependencies of the code step. Once added, you can import and use them in your code just as you would in a Node.js project.
Preview the step
A preview of the code is shown on the step itself in the flow, so you can see what each code step does without opening it. This makes it easy to scan a flow and understand where your custom logic runs.
Configure how the step handles failures
A code step has a few optional settings that control what happens when something goes wrong:
- Continue on error: By default, if the code throws an error the flow stops at that step. Enable this option to let the flow continue to the next step even when the code fails.
- Retries: Set the number of times the step should automatically retry if it fails before the flow gives up. This is useful when the code depends on an external service that may be briefly unavailable.
You can also record an estimated time saved per execution, which feeds into your automation's reporting on the impact of the flow.
Test before you activate
Run the flow against sample data to confirm the code step behaves as expected before it processes live messages. Check that the value the step returns is what later steps expect, and that any error handling behaves the way you want. Once you are happy with the result, activate the flow.
0 comments
Please sign in to leave a comment.