Home›Blog›AI Automation
AI Automation

GoHighLevel Custom Code Action: 6 Practical JavaScript Snippets for Workflows

How the GoHighLevel Custom Code action works, with six tested JavaScript snippets you can paste into your workflows today.
Saleem Akhter
6 min read

Most GoHighLevel workflows can be built from the standard actions. Every so often, though, you need a small piece of logic the builder does not offer: tidy a phone number, split a full name, work out the next business day, or combine several answers into a score. That is what the GoHighLevel Custom Code action is for.

This guide explains how the action works and gives six practical JavaScript snippets you can adapt. Each one is short, readable and returns a value you can use in the next steps of your workflow.

How the Custom Code action works

  • Inputs. In Property to Include in Code you add key–value pairs. Each value can be fixed or mapped from the contact or an earlier step. In the code you read them as inputData.yourKey.
  • Code. You write JavaScript (HighLevel also lists Python as an option). The code runs inside an async function.
  • Output. You assign an object (or an array of objects) to output. Later steps can use its values, for example to update a contact field or decide an if/else branch.
  • Test. Run the step’s test with sample values so the output fields appear for the steps that follow.

The simplest example, from HighLevel’s own help article, adds two numbers:

// Inputs: number1, number2
const sum = Number(inputData.number1) + Number(inputData.number2);
output = { result: sum };
Before you start: the Custom Code action is treated as a premium workflow action in many accounts, which can add a small charge per execution. Check your plan, and use a standard action whenever one exists.

1. Clean a phone number into international format

Forms collect phone numbers in every possible format. This snippet strips spaces and symbols and adds a default country code when the number has none, so SMS steps receive something consistent.

// Inputs: phone, defaultCountryCode (e.g. "1" for US/Canada, "44" for the UK)
const raw = String(inputData.phone || '').trim();
let digits = raw.replace(/[^\d+]/g, '');

if (digits.startsWith('00')) digits = '+' + digits.slice(2);   // 0044... becomes +44...
if (!digits.startsWith('+')) {
  const cc = String(inputData.defaultCountryCode || '1');
  digits = '+' + cc + digits.replace(/^0+/, '');               // drop the trunk zero
}

const valid = /^\+\d{8,15}$/.test(digits);
output = { phone: valid ? digits : '', phoneValid: valid };

Map phone back to the contact’s phone field, and use phoneValid in an if/else branch to send invalid numbers to a manual review task instead of an SMS step.

2. Split a full name into first and last name

// Input: fullName
const parts = String(inputData.fullName || '').trim().replace(/\s+/g, ' ').split(' ');
const cap = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '');

const firstName = cap(parts.shift() || '');
const lastName = parts.map(cap).join(' ');

output = { firstName, lastName };

Useful when a form or an imported list has a single “Name” field. The capitalisation is deliberately simple; names such as “McDonald” or “van der Berg” may need a manual check.

3. Score a lead from form answers

If your intake form asks about budget, timeline and decision-making, this snippet turns the answers into a number and a band your workflow can branch on. Change the values to match your own form options and sales experience.

// Inputs: budget, timeline, decisionMaker, service
const points = {
  budget:   { 'under-1k': 0, '1k-5k': 10, '5k-plus': 20 },
  timeline: { 'this-month': 20, '1-3-months': 10, 'just-researching': 0 },
};

let score = 0;
score += points.budget[inputData.budget] ?? 0;
score += points.timeline[inputData.timeline] ?? 0;
if (String(inputData.decisionMaker).toLowerCase() === 'yes') score += 15;
if (inputData.service) score += 5;

const band = score >= 40 ? 'hot' : score >= 20 ? 'warm' : 'cold';
output = { score, band };

Write score to a number custom field and add a tag based on band. The point values are examples, not benchmarks — tune them against the leads that actually became customers.

4. Work out the next business day

Handy for follow-up tasks and “we’ll call you on…” messages that should never land on a weekend.

// Input (optional): daysAhead = number of business days to add (default 1)
const add = Math.max(1, Number(inputData.daysAhead) || 1);
const d = new Date();
let added = 0;

while (added < add) {
  d.setDate(d.getDate() + 1);
  const day = d.getDay();               // 0 = Sunday, 6 = Saturday
  if (day !== 0 && day !== 6) added++;
}

const iso = d.toISOString().slice(0, 10);   // e.g. 2026-11-03
const label = d.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' });
output = { nextBusinessDate: iso, nextBusinessLabel: label };

The date is calculated in the server’s time zone, so allow for that if your business is far from UTC. Public holidays are not included; keep a list of them and skip those dates if you need to.

5. Days since a date

Use this to branch on how long it has been since a last visit, last purchase or last reply — for example to choose between a gentle reminder and a reactivation message.

// Input: date = a date string from a contact field, e.g. 2026-08-14
const then = new Date(inputData.date);
if (isNaN(then)) {
  output = { daysSince: -1, known: false };
} else {
  output = { daysSince: Math.floor((Date.now() - then.getTime()) / 86400000), known: true };
}

6. Turn a comma-separated answer into clean tags

Multi-select form questions often arrive as one string. This snippet tidies it into a consistent list you can use to add tags.

// Input: answers, e.g. "Email Marketing, SMS ,  Funnels"
const tags = String(inputData.answers || '')
  .split(',')
  .map((t) => t.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, ''))
  .filter(Boolean);

output = {
  tagList: tags.join(', '),   // "email-marketing, sms, funnels"
  firstTag: tags[0] || '',
  count: tags.length,
};

Good practice for Custom Code steps

  • Keep each step to one job. Small snippets are easier to test and replace.
  • Never trust the input. Convert numbers with Number(), default empty values and handle invalid dates, as the snippets above do.
  • Always set output, even when something goes wrong, so later steps have predictable values to branch on.
  • Do not put secrets in the code. Anyone with access to the workflow can read it.
  • Name the step clearly, such as “Clean phone number”, so the workflow stays readable.
  • Prefer built-in actions. Use custom code only where the builder genuinely cannot do the job.

For moving data in and out of GoHighLevel rather than transforming it, see our guides to the GoHighLevel API and sending leads to Google Sheets.

Frequently asked questions

Which language should I use?

JavaScript is the default and the one most examples use. HighLevel also lists Python; choose whichever your team can maintain.

Can the code call external APIs?

HighLevel’s help article does not document network access from the Custom Code action. For calling external services, the Custom Webhook action is the documented route.

Why are my output fields not available in later steps?

Run the step’s test with sample inputs first. The output fields appear for later steps once a test has produced them.

Is there a size or time limit?

HighLevel’s article does not list one. Keep snippets short and fast; long-running logic belongs on your own server or in an integration platform.

Ready to Implement This?

Let GHL Nexa set this up for you. Book a free 30-minute strategy call today.

SHARE THIS ARTICLE