Code fields
A code field runs a snippet of JavaScript for each row, with the row’s other fields available as input, and stores the returned value. It’s for logic that’s beyond a formula — parsing, custom formatting, multi-step calculations.
Code runs inside a secure sandbox (a QuickJS WebAssembly isolate): no network, no filesystem, no access to the host. It’s read-only like all computed fields, and recomputes automatically when the row changes.
// Row values are available on `fields`return fields.Price * fields.Qty;Writing code
Section titled “Writing code”Your snippet’s result is the cell’s value. You can either return a bare expression’s value or use an explicit return:
// Bare expression — its value is the resultfields.Price * fields.Qty// Or multi-line with an explicit returnconst subtotal = fields.Price * fields.Qty;const withTax = subtotal * 1.2;return Math.round(withTax * 100) / 100;The input API
Section titled “The input API”fields— an object of the row’s values keyed by field name:fields.Name,fields["Unit Price"].record.fields— the same object, if you prefer the fuller form.
Missing/blank values come through as null.
Return values
Section titled “Return values”- Strings, numbers, and booleans are stored as-is.
- Objects and arrays are stored as their JSON string.
undefined/nullstore as an empty cell.- Output is capped at 10,000 characters.
// Format a phone numberconst d = String(fields.Phone || "").replace(/\D/g, "");return d.length === 10 ? `(${d.slice(0,3)}) ${d.slice(3,6)}-${d.slice(6)}` : fields.Phone;The sandbox
Section titled “The sandbox”Code fields are safe by construction:
- No host access —
fetch,process,require,import, and the filesystem are all unavailable. - CPU limit — each run is interrupted after 1 second, so an infinite loop can’t hang anything.
- Memory limit — 16 MB per run; a runaway allocation is capped.
- Output limit — results are truncated at 10,000 characters.
If your code throws or exceeds a limit, the cell is left blank and the failure is recorded in the run log.
How it recomputes
Section titled “How it recomputes”Unlike formulas and templates (which recompute instantly as you type in a cell), code runs asynchronously — a moment after a write — because the sandbox runs server-side. In practice the value appears a beat after you change an input.
Ordering: formula and template fields compute first, then code. So:
- A code field can read a formula’s or template’s up-to-date value.
- A formula that reads a code field’s value picks it up on the next write to the row.
- Chained code fields may lag one write behind.
Behavior & limits
Section titled “Behavior & limits”- Read-only and materialized — filtering, sorting, API reads, and public shares all see the computed value.
- Same-row only — code sees the current row’s fields, not other rows or linked records.
- Deterministic use recommended — since results are stored, prefer logic that depends only on the row’s inputs.