How to Use the Custom Code Workflow Action in Sparkforge
Custom Code is a premium workflow action that runs JavaScript with access to inputData from prior steps. It supports HTTP requests, console logging, AI-assisted code generation, and a mandatory test step before output is usable downstream.
Custom Code lets you drop JavaScript into a workflow when no pre-built action covers what you need — reformat dates, call an external API, run math, parse strings, or build branching logic. It's a Premium action.
Add the action
In the workflow, click the + icon and search for Custom Code.
Pass values into the code
Use the Property fields to map data from previous steps into a dictionary called inputData.
- Enter a Key (e.g.,
firstName). - Pick a Value using the custom value picker.
- Click Add Property to add more.
Reference values inside the code as inputData.firstName or inputData['firstName'].
Write the code
- JavaScript is the only language.
- The editor pre-fills a sample. Edit it directly.
- Output must be a JavaScript object or array of objects — returned from the code, not stored elsewhere.
- Use
console.log()freely; logs surface in execution history.
Make external HTTP requests
Click HTTP Request above the code editor and choose a method:
- GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS.
The boilerplate is inserted at the bottom of the editor; fill in the URL, headers, and body.
Format and test
- Click Format Code to apply consistent indentation and spacing.
- Click Test your Code. A modal opens.
- If you mapped properties, fill in Test Setup with sample values.
- Run the test. A success result lets the output flow downstream; a failure means you have to fix the code first.
Testing is mandatory. Untested code can't pass output to subsequent actions.
Code with AI (Beta)
Skip writing from scratch — describe the function in plain English and let AI generate it.
- Add a Custom Code action.
- Click Build with AI.
- Describe what you want (e.g., “Convert a date from MM-DD-YYYY to YYYY-MM-DD”).
- Click Generate. Review the output.
- If it's not right, refine the prompt and click Regenerate.
- Click Use Code to insert it into the action.
Things that trip people up
- Custom values aren't passed during testing — only contact info is. Don't write tests that depend on custom values working in the test sandbox.
- Untested code returns no output downstream. Test before saving the workflow.
- Use the
inputDatadictionary; values aren't auto-injected as bare variables.
Common use cases
- Reformat phone numbers, dates, or names before sending to another system.
- Hit an external API — enrichment service, internal tool, or webhook target.
- Run math (interest, discount, weighted scores) you can't express in field formulas.
- Pull substrings out of email or SMS bodies (e.g., parse a tracking number).
- Custom routing — decide which list, tag, or pipeline a contact lands in based on multi-condition logic.
Frequently Asked Questions
Which language can I write Custom Code in?
How do I read values from earlier workflow steps?
Can my code call an external API?
Why can't downstream steps see my output?
Is Code with AI reliable enough to ship?
Was this article helpful?
Thanks for the feedback.