Custom Code workflow action
The Custom Code action runs custom JavaScript inside a workflow when no pre-built action does what you need. Use it to extend workflow functionality, execute custom JavaScript, integrate with external services, and perform complex calculations and transformations. It is a premium action, and the code's output must be a JavaScript object or an array of objects.
Add a Custom Code action
In Workflows, click the + icon to add an action, then search for Custom Code and select it. It is listed under Internal Tools Actions in the Workflow actions catalog; for how triggers and actions fit together, see Workflows Overview.
In the action modal, Action Name defaults to Custom Code and Language is set to Javascript, which is the default language.
Pass values into the code with properties
Properties pass values from earlier triggers or actions into the code. The values are placed in a dictionary called InputData.
Enter the property name in the Key input field.
Select the corresponding value with the custom-value picker.
Click Add Property for each additional property.
Access the values in code with inputData.keyName or inputData['keyName']. For example, a property keyed number1 mapped to the contact's phone and a property keyed number2 mapped to the user's phone are read inside the code as inputData.number1 and inputData.number2.
Write and format the code
Write the code in the code editor, where sample code is pre-populated for reference. The output must be written here too, and it must be a JavaScript object or an array of objects; the editor displays the note: Output should be a JavaScript Object or Array of Objects.
// This is wrapped in an async function
// You can use await throughout the function
const sum = inputData.number1 + inputData.number2
// Note: Output should be a JavaScript Object or Array of Objects.
output = { result: sum }The Format Code button at the bottom of the code editor reformats the code for readability, improving indentation, spacing, and line breaks, and making code blocks, functions, and sections easier to identify.
Test your code
Testing is mandatory: output is unavailable to subsequent steps until the code is tested. Test the code from the action modal:
Click Test your Code. A new popup opens.
If properties were added, open the Test Setup tab and enter sample values.
If no properties were added, check the response directly.
Click Test your Code to run the test.
If the code has no errors, the result displays Test Result Success. If the code contains errors, the result displays Test Result Failed; correct the code and test again.
Custom values are not passed when testing code: only contact information is passed, and other properties used in the code are not passed during testing.
HTTP requests and console logs
The action supports external HTTP requests and captures console.log output from your code.
Click the HTTP Requests button above the code editor, then select a method: Get Method, Post Method, Put Method, Patch Method, Delete Method, Head Method, or Options Method. Selecting a method populates request code at the bottom of the code editor.
Enhanced console support captures and logs all console.log output from user code, which helps you debug the code and monitor its behavior.
Check input values in execution logs
You can review the input values your code received when the workflow ran. Open the execution you want to check, click more details, and review the input values in the execution logs. For how to work with execution logs overall, see Workflow History and Logs.
Return a response directly
Returning a response directly from custom code improves how asynchronous code is handled: it makes custom async code easier to write, debug, and manage, simplifies asynchronous operations, and improves script efficiency.
Build code with AI
Code with AI (Beta) generates custom JavaScript from a plain-language description of what you want the action to do. Previously, users had to write JavaScript from scratch, manually map input properties, test and debug manually, have sufficient programming knowledge, and invest more time and technical skill. Code with AI adds:
AI-Powered Code Generation: describe the functionality in plain language and receive JavaScript.
Automated Property Integration: the AI incorporates relevant input properties based on your description.
One-Click Implementation: review and insert the generated code.
Regenerate if Needed: click Generate again for a fresh result.
To build code with AI:
Select the Custom Code action in a workflow.
Click Build with AI.
Describe the desired functionality, for example: “I have an API that returns a date in MM-DD-YYYY format. Can you help me convert it to YYYY-MM-DD.”
Click Generate.
Review the generated code.
If changes are required, describe them in the text box and click Regenerate.
Click Use Code to insert the result into the workflow.
Be as specific as possible in your prompt for the best results.
Points to remember
Testing the code is mandatory; no output is available to subsequent actions for untested code.
When you test, only contact information is passed — custom values and other properties used in the code are not passed during testing.
Use the Property fields to assign key names and map values from previous steps, then access them with
inputData.keyNameorinputData['keyName'].