Skip to content

Code Helpers โ€‹

Code helpers are the $-prefixed functions available to form code. They cover reading and writing field values, inspecting selections, working with repetitive grids, aggregating data, and a curated set of JavaScript built-ins.

Contexts โ€‹

Every helper lists the execution contexts it can be used in:

TokenContextAccess
scriptOn Load and button script actionsRead & write
visVisibility rulesRead-only
valValidation rulesRead-only
textText Display {{ }} expressionsRead-only

All means a helper works in all four contexts. The helpers that mutate data โ€” $set, $setIn, $grid(...), and $state(name, value) โ€” are script only.

Field accessors โ€‹

ReferenceReturnsContextsWhat it does
$get(fieldId)anyAllRead a field value by exact ID from anywhere in the form
$getIn(fieldId)anyAllRead a field value relative to the current repeating-grid row
$set(fieldId, value)voidscriptWrite a field value and trigger reactivity
$setIn(fieldId, value)voidscriptWrite a field value within the current repeating-grid row
$getAll(fieldId)Record | undefinedAllGet all values matching a field ID across repeating-grid rows

Data helpers โ€‹

ReferenceReturnsContextsWhat it does
$includes(fieldId, value)booleanAllCheck if a field value contains the given item
$isEmpty(fieldId)booleanAllCheck if a field is empty
$isNotEmpty(fieldId)booleanAllCheck if a field has a meaningful value
$option(fieldId)ResolvedOption[]textResolve the selected option objects for a field, including token-aware labels
$selected(fieldId)stringtextResolve the selected option labels for a field as comma-separated text

Variable access โ€‹

These resolve the runtime namespaces โ€” see Runtime Variables for the full breakdown of what each one holds.

ReferenceReturnsContextsWhat it does
$.selfobjectAllSession context object for the logged-in user
$.formobjectAllCurrent form metadata such as id, name, and viewer mode
$.stateobjectAllForm-scoped runtime state set by scripts. Not submitted or persisted
$.variableobjectvis script textGlobal data variables from the registry (read-only, overridable per theme). Script-type variables use $.fn, image-type use $.image
$.imageobjectvis script textImage variables from the registry (read-only, overridable per theme via images/images_dark). Returns sl:// or URL strings
$.fn.name(...args)anyvis script textCall a registry function. Function bodies receive read-only runtime namespaces; callers perform mutations with $set or $state using returned values. Pass reactive values as args for dependency tracking
$state(name)anyAllRead form-scoped runtime state
$state(name, value)anyscriptSet form-scoped runtime state and return the written value

Repeating-grid row context โ€‹

Available inside Repetitive Grid rows. Outside a repeating grid, $index is -1.

ReferenceReturnsContextsWhat it does
$indexnumberval script textCurrent repeating-grid row number context (-1 outside repeating grids)
$parent_pathstringval script textCurrent repeating-grid row path prefix (for example, items.0:)

Repeating-grid row controls โ€‹

Repetitive grids only

These helpers only work with a Repetitive Grid (d_grid_rep). Plain Grid Layout (d_grid) elements are layout containers and do not register row controls.

$grid(gridId) returns a row controller (GridOps) for the grid; call its methods to manipulate rows. All row controls are script only.

ReferenceReturnsWhat it does
$grid(gridId)GridOpsGet the row controller for a repeating grid (d_grid_rep) by ID
$grid(id).addRow()booleanAdd a new row to a repeating grid, respecting maxRows
$grid(id).removeRow(index?)booleanRemove the last row, or remove a specific 1-based row number
$grid(id).getRowCount()numberGet the current repeating-grid row count
$grid(id).moveRow(from, to)booleanMove a row from one 1-based row number to another
$grid(id).duplicateRow(index)booleanDuplicate the row at the given 1-based row number

Repeating-grid aggregates โ€‹

Roll up values across every row of a repeating grid. Available in all contexts.

ReferenceReturnsWhat it does
$sum(fieldId)numberSum numeric values across repeating-grid rows
$count(fieldId)numberCount non-empty rows for a field across the grid
$avg(fieldId)numberAverage numeric values across repeating-grid rows
$min(fieldId)numberSmallest numeric value across repeating-grid rows
$max(fieldId)numberLargest numeric value across repeating-grid rows

Built-ins โ€‹

A curated set of standard JavaScript built-ins is available in all contexts (scripts, visibility, validation, and text expressions).

ReferenceReturnsWhat it does
Math.round(value)numberMath helpers like round, floor, ceil, min, and max
Number(value)numberCoerce a value to a number
String(value)stringCoerce a value to a string
Boolean(value)booleanCoerce a value to true or false
parseInt(value, 10)numberParse an integer from text
parseFloat(value)numberParse a decimal number from text
JSON.stringify(value)stringSerialize or parse JSON values
Array.isArray(value)booleanCheck if a value is an array
Object.keys(value)string[]Inspect object keys or entries
Date.now()numberUse Date static helpers without constructing objects
isNaN(value)booleanCheck whether a value is NaN
isFinite(value)booleanCheck whether a value is finite
InfinitynumberNumeric infinity constant
NaNnumberNot-a-number constant

See also: Scripts overview ยท Runtime Variables ยท Examples