How to Use the Custom Code Workflow Action in Sparkforge

By Sparkforge Support Team ·Last reviewed May 3, 2026

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.

  1. Enter a Key (e.g., firstName).
  2. Pick a Value using the custom value picker.
  3. 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

  1. Click Format Code to apply consistent indentation and spacing.
  2. Click Test your Code. A modal opens.
  3. If you mapped properties, fill in Test Setup with sample values.
  4. 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.

  1. Add a Custom Code action.
  2. Click Build with AI.
  3. Describe what you want (e.g., “Convert a date from MM-DD-YYYY to YYYY-MM-DD”).
  4. Click Generate. Review the output.
  5. If it's not right, refine the prompt and click Regenerate.
  6. 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 inputData dictionary; 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?
JavaScript only. The editor sets it as the default and there is no other runtime.
How do I read values from earlier workflow steps?
Map them into the Property fields with a Key, then read them in code as inputData.keyName or inputData['keyName'].
Can my code call an external API?
Yes. Click HTTP Request above the editor, pick a method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS), and the boilerplate gets inserted into the code.
Why can't downstream steps see my output?
You haven't tested the code. Test results enable the output for use in later actions — it's a hard requirement.
Is Code with AI reliable enough to ship?
It's a starting point. Read the generated code, run the test, and tweak as needed. Treat it like a draft from a junior dev, not a finished product.

Was this article helpful?