appointment_label, and let the flow route based on whether the timestamp was
valid.
If you use a single- or multi-prompt agent, see Code Tool.

A Code node on the conversation flow canvas.
When to use a Code node
Configure a Code node
Add a Code node

Code in the conversation flow action-node menu.
Open the code editor
Write JavaScript
dv or metadata and return a JSON-serializable value.
Objects are the easiest return type to map into response variables.Store fields as variables
appointment_is_valid to
valid and appointment_label to appointment_label.See Store response variables for nested and
array paths.Configure execution and transitions
Test the code
console.log() output appear below the
editor.Test values stay in the dashboard and don’t change the live agent. The
dashboard test doesn’t populate metadata, so metadata-dependent code must
handle an empty object during testing.JavaScript environment
The code runs inside a QuickJS sandbox. Top-levelawait is supported.
dv: dynamic variables
Read dynamic variables as properties of dv. All
values in dv are strings, including values stored by earlier nodes.
dv.user_number, not {{user_number}}, inside JavaScript. Runtime values
such as call_id, chat_id, session_type, direction, user_number, and
agent_number are available when they apply to the current session.
dv inside JavaScript. {{...}}
template substitution isn’t available inside code.metadata: call or chat metadata
Read metadata passed when you create the phone call
or chat.
dv, they aren’t limited
to strings.
fetch(url, options): HTTP requests
fetch() supports HTTP and HTTPS URLs, request methods, string-valued headers,
and request bodies. The returned response supports status, ok,
statusText, url, headers.get(), text(), and json().
fetch() requests originate from 35.166.138.221. If your public
API restricts inbound traffic by IP address, allowlist 35.166.138.221/32.
console.log(): test output
Use console.log() while testing. Logs appear in Run Code results. They
aren’t added to the live code result or shown as Code node logs in call logs.
Runtime limits
Array, Date,
JSON, Map, Math, Promise, RegExp, and Set. Node.js modules, browser
DOM APIs, require, import, and Intl aren’t available.
Store response variables
Response variables copy fields from the full return value into dynamic variables. For this return value:null, Retell skips that variable without
failing the execution.
Response-variable extraction uses the full return value, even when the result
sent to the agent is capped at 15,000 characters.
Track execution status
In the Code dialog, find Store Fields as Variables and entersummary_status in the variable-name field beside the fixed Success status label. Save the code configuration. Use a name without {{ }} that differs from your response-variable names, or leave it blank to skip storing status.

Store code execution status as summary_status, separately from returned fields.
success when the code completes and failure when execution fails, including an uncaught error or timeout. Returning { ok: false } still counts as successful execution; map ok as a response variable to check that business result. Tools that don’t run leave the status variable unchanged. The API field is execution_status_variable.
Control transition timing
Execution mode defaults to Wait for completion. Retell waits for the code result before evaluating transitions, so returned fields are available to conditions and the next node. Choose Run in background (async) only when later nodes can proceed before the result and response variables are available. The API represents this choice withwait_for_result.
Waiting mode offers Talk While Waiting and Play typing sound. These controls are hidden in background mode. Caller interruptions can still affect speech timing.
To branch on execution status, configure Success status as above and use a transition condition such as {{summary_status}} == "failure". Choose Wait for completion so the condition uses the current execution’s result.
Use transition conditions that
check stored result fields before the agent confirms an action succeeded.
Node settings
Use Code node safely
- Don’t put API keys, credentials, or sensitive tokens in code,
dv, ormetadata. - Use
fetch()for low-risk HTTP reads. Put authenticated requests and state-changing operations behind a custom function on your backend. - For critical routing, provide a safe else path. A timeout, thrown error, or sandbox failure doesn’t retry automatically and doesn’t extract response variables.
FAQ
Can I use npm packages or browser APIs?
Can I use npm packages or browser APIs?
require, import, Node.js modules, browser DOM APIs, or Intl. Use the available JavaScript built-ins and fetch().Can I use built-in system variables in the code?
Can I use built-in system variables in the code?
dv, including dv.call_id, dv.user_number, and dv.agent_number when they apply. Use dv.name syntax to access them. {{...}} template substitution isn’t available inside JavaScript.What happens if the code times out or throws an error?
What happens if the code times out or throws an error?
try/catch for expected errors and return a structured fallback such as { "ok": false, "error": "lookup failed" }. For critical routing, configure a safe else path.Why did the agent talk with Talk While Waiting off?
Why did the agent talk with Talk While Waiting off?
Can I use async/await?
Can I use async/await?
await is supported, including for fetch() calls.Is there a limit on the result size?
Is there a limit on the result size?

