# **Context:** Catalog Variable API spec: The 30+ variable type functions used inside `VariableSet.variables` and `CatalogItem.variables` objects. Each function creates a specific type of input field on a catalog request form. All variable types share a common base configuration plus type-specific properties.

```typescript
// All variable functions are imported from @servicenow/sdk/core
import {
    SingleLineTextVariable, MultiLineTextVariable, WideSingleLineTextVariable,
    SelectBoxVariable, MultipleChoiceVariable, CheckboxVariable, YesNoVariable,
    ReferenceVariable, LookupSelectBoxVariable, LookupMultipleChoiceVariable,
    RequestedForVariable, DateVariable, DateTimeVariable, DurationVariable,
    EmailVariable, UrlVariable, IpAddressVariable, MaskedVariable,
    LabelVariable, RichTextLabelVariable, HtmlVariable, BreakVariable,
    ListCollectorVariable, NumericScaleVariable,
    UIPageVariable, CustomVariable, CustomWithLabelVariable,
    ContainerStartVariable, ContainerEndVariable, ContainerSplitVariable,
    AttachmentVariable,
} from '@servicenow/sdk/core'

// ─── SHARED BASE PROPERTIES (all variable types inherit these) ───
// These are defined in VariableConfig / BaseVariableConfig:
const _sharedBaseProperties = {
    question: '',           // string, mandatory — label/question shown to the user
    order: 100,             // number, optional — display order within the form
    active: true,           // boolean, optional — whether the variable is active
    mandatory: false,       // boolean, optional — field must have a value; cannot be true with hidden or readOnly
    readOnly: false,        // boolean, optional — field is display-only; cannot be true with mandatory
    hidden: false,          // boolean, optional — field is not shown; cannot be true with mandatory
    defaultValue: '',       // string | typed default, optional — default value
    helpText: '',           // string, optional — help text shown below the field
    helpTag: '',            // string, optional — help tag identifier
    showHelp: false,        // boolean, optional — show help icon
    instructions: '',       // string, optional — instructions above the field
    tooltip: '',            // string, optional — tooltip on hover
    exampleText: '',        // string, optional — example value text
    conversationalLabel: '', // string, optional — label used in Virtual Agent conversations
    disableInitialSlotFill: false, // boolean, optional — disable VA slot filling on load
    width: 100,             // 25 | 50 | 75 | 100, optional — field width percentage
    attributes: '',         // string, optional — additional field attributes string
    readRoles: [],          // (string | Role)[], optional — roles that can read this variable
    writeRoles: [],         // (string | Role)[], optional — roles that can modify this variable
    createRoles: [],        // (string | Role)[], optional — roles that can create instances
    visibleBundle: true,    // boolean, optional — visible in bundles
    visibleGuide: true,     // boolean, optional — visible in guided tours
    visibleStandalone: true, // boolean, optional — visible standalone
    visibleSummary: true,   // boolean, optional — visible in order summary
    visibility: 'Always',   // 'Always' | 'Bundle' | 'Standalone', optional
    pricingDetails: [],     // { amount: number, currencyType: string, field: string }[], optional
    pricingImplications: false, // boolean, optional
    deliveryPlan: '',       // string, optional
    alwaysExpand: false,    // boolean, optional
    removeFromConversationalInterfaces: false, // boolean, optional
    mapToField: false,      // boolean, optional — map variable value to a record field
    field: '',              // string, optional — record field to map to (requires mapToField: true)
    $meta: { installMethod: 'once' }, // optional (SDK v4.13.0+), every variable type: { installMethod?: 'first install' | 'demo' | 'once', useEsLatest?: boolean }
                            // — not 'demo' here: demo data is only for rows of tables that do not extend sys_metadata (demo-data-guide, SDK v4.14.2); variables have no server script, so useEsLatest is moot
    // Dynamic default value — these three properties always work together.
    // This auto-populates THIS variable's value by dot-walking from another variable's
    // referenced record. It is NOT a visibility or choice-filtering mechanism:
    // use `CatalogUiPolicy` to show/hide variables and a reference qualifier
    // (`referenceQualCondition` / `dynamicRefQual` / `referenceQual`) to filter options.
    useDynamicDefault: false, // boolean, optional — must be true to enable the dynamic default
    dependentQuestion: 'requestedFor', // optional — the source variable whose selected record is dot-walked
    // type: string | ReturnType<typeof ReferenceVariable> | ReturnType<typeof RequestedForVariable> (union widened SDK v4.10.1+; declared once on BaseVariableConfig, so every variable type accepts it)
    // The source must be a `RequestedForVariable` or a `ReferenceVariable` — it needs a referenced record to dot-walk from.
    // The source must also be declared BEFORE this variable in the `variables` object.
    // PREFER the source variable's key name as a string, e.g. 'requestedFor'.
    // The only supported object form is a VariableSet dot-walk, e.g. `employeeSet.variables.requestedFor`.
    // A direct reference to a variable's own const (e.g. `dependentQuestion: requestedForVar`) is NOT supported, even though the widened union type-checks it.
    dotWalkPath: 'manager', // string, optional — field path from the source variable's referenced record, e.g. 'manager' or 'department.name'
    unique: false,          // boolean, optional — enforce unique values
    postInsertScript: '',   // string, optional — script run after record insert
    readScript: '',         // string, optional — script run when reading the value
    description: '',        // string, optional
    global: false,          // boolean, optional
    category: '',           // string, optional
    layout: 'normal',       // 'normal' | '2across' | '2down', optional — container layout
}

// ─── TEXT VARIABLES ───

// Single line text input
SingleLineTextVariable({
    question: '',           // mandatory
    validateRegex: '',      // string | Record<'question_regex'>, optional — regex validation pattern or reference
    // + all base properties
})

// Multi-line text area
MultiLineTextVariable({
    question: '',           // mandatory
    // + all base properties
})

// Wide single line text (full-width input)
WideSingleLineTextVariable({
    question: '',           // mandatory
    // + all base properties
})

// Email address input (with format validation)
EmailVariable({
    question: '',           // mandatory
    // + all base properties
})

// URL input (with format validation)
UrlVariable({
    question: '',           // mandatory
    // + all base properties
})

// IP address input (v4 or v6)
IpAddressVariable({
    question: '',           // mandatory
    // + all base properties
})

// Masked/password field (input is obfuscated)
MaskedVariable({
    question: '',           // mandatory
    // + all base properties
})

// ─── SELECTION VARIABLES ───

// Dropdown select box (single selection)
SelectBoxVariable({
    question: '',           // mandatory
    // + all base properties
    // Choices are configured in the catalog builder UI or via choice definitions
})

// Radio button multiple choice (single selection displayed as radio buttons)
MultipleChoiceVariable({
    question: '',           // mandatory
    // + all base properties
})

// Checkbox (true/false toggle)
CheckboxVariable({
    question: '',           // mandatory
    defaultValue: false,    // boolean, optional
    selectionRequired: false, // boolean, optional - the checkbox must be ticked (written to the variable's mandatory column);
                            // takes the place of `mandatory`, and
                            // cannot be true together with readOnly or hidden
    readOnly: false,        // boolean, optional
    hidden: false,          // boolean, optional
    // + base properties, EXCEPT `mandatory` (TS2353 - use selectionRequired)
})

// Yes / No dropdown (equivalent to true/false but displayed as Yes/No options)
YesNoVariable({
    question: '',           // mandatory
    // + all base properties
})

// ─── REFERENCE VARIABLES ───

// Reference to a record in another table
ReferenceVariable({
    question: '',           // mandatory
    referenceTable: 'incident', // string (TableName), mandatory — table being referenced
    useReferenceQualifier: 'simple', // 'simple' | 'dynamic' | 'advanced', optional
    referenceQualCondition: '', // string, optional — encoded query for 'simple' qualifier
    dynamicRefQual: '',     // string | Record<'sys_filter_option_dynamic'>, optional — for 'dynamic'
    referenceQual: '',      // string, optional — advanced qualifier script, for 'advanced'
    // + all base properties
})

// Lookup select box (reference field presented as a dropdown populated from another table)
LookupSelectBoxVariable({
    question: '',           // mandatory
    // + all base properties
})

// Lookup multiple choice (reference field as multi-select checkboxes)
LookupMultipleChoiceVariable({
    question: '',           // mandatory
    // + all base properties
})

// Requested For — user reference pre-populated with the requesting user
RequestedForVariable({
    question: '',           // mandatory (typically 'Requested For' or 'On behalf of')
    // + all base properties
})

// ─── DATE / TIME VARIABLES ───

DateVariable({
    question: '',           // mandatory
    defaultValue: '',       // string (date string), optional
    // + all base properties
})

DateTimeVariable({
    question: '',           // mandatory
    defaultValue: '',       // string (ISO datetime), optional
    // + all base properties
})

DurationVariable({
    question: '',           // mandatory
    // + all base properties
})

// ─── DISPLAY / LAYOUT VARIABLES ───

// Non-input label (static text displayed on the form)
LabelVariable({
    question: '',           // mandatory — the label text to display
    // + base properties (mandatory/readOnly/hidden not applicable)
})

// Rich text label (HTML-formatted static content)
// NOTE: RichTextLabelVariable does NOT accept `question`; the content lives in `richText`.
RichTextLabelVariable({
    richText: '',           // string, mandatory — rich-text / HTML content
    // + base properties (excluding `question`; mandatory/readOnly/hidden are not accepted - TS2353)
})

// HTML content block (embedded HTML in the form)
HtmlVariable({
    question: '',           // mandatory — HTML string
    // + base properties
})

// Horizontal line break / separator
// NOTE: BreakVariable does NOT accept `question` — it's a visual separator only.
BreakVariable({
    // base properties only.
})

// Container start (begin a collapsible section)
// NOTE: `question` is the container title: mandatory with `displayTitle: true`, optional otherwise.
ContainerStartVariable({
    question: 'Request Details', // string, mandatory when displayTitle is true
    displayTitle: true,     // boolean, optional — show the question as the container title
    layout: 'normal',       // 'normal' | '2across' | '2down', optional
    // + base properties
})

// Container split (divider inside a container)
// NOTE: ContainerSplitVariable does NOT accept `question`.
ContainerSplitVariable({
    // base properties only.
})

// Container end (close a container section)
// NOTE: ContainerEndVariable does NOT accept `question` — it just closes a container.
ContainerEndVariable({
    order: 900,             // number, optional — must be higher than the matching ContainerStartVariable
    // also: active, disableInitialSlotFill — no other properties
})

// ─── SPECIAL VARIABLES ───

// List collector (multi-select from a reference table)
ListCollectorVariable({
    question: '',           // mandatory
    listTable: 'incident',  // TableName, mandatory — the table being referenced
    referenceQual: '',      // string, optional — encoded query to filter the reference list
    // + base properties
})

// Numeric scale / rating (e.g., 1-5 satisfaction score)
NumericScaleVariable({
    question: '',           // mandatory
    // + all base properties
})

// Attachment upload field
AttachmentVariable({
    question: '',           // mandatory
    // + base properties
})

// Embedded UI Page
UIPageVariable({
    question: '',           // mandatory — UI Page name or sys_id
    // + base properties, EXCEPT mandatory/readOnly/hidden (not accepted - TS2353)
})

// Custom variable (advanced — render the variable with your own component)
// Set the property for EACH context the item is ordered in. All five are optional and the build does not require or
// diagnose any of them, but a variable with none set renders BLANK in every context. `macro` + `widget` can be combined
// (Platform UI + Service Portal), and `summaryMacro` pairs with `macro`.
CustomVariable({
    question: '',           // mandatory
    macro: '',              // string | Record<'sys_ui_macro'> | UiMacro, optional — Jelly macro for Classic/Platform UI catalog forms.
                            // A UiMacro() object from the same project is accepted as of SDK v4.14.0; also Now.ref() or a sys_id
    summaryMacro: '',       // string | Record<'sys_ui_macro'> | UiMacro, optional — read-only rendering on confirmation and
                            // summary pages (UiMacro accepted as of SDK v4.14.0); omit for the default summary rendering
    widget: '',             // string | Record<'sp_widget'> | SPWidget, optional — Service Portal widget; an SPWidget() object from
                            // the same project is accepted as of SDK v4.14.0 (it was a type error before)
    macroponent: '',        // string | Record<'sys_ux_macroponent'>, optional — Next Experience / UI Builder workspaces
    topicBlock: '',         // string | Record<'sys_cs_topic'>, optional — Virtual Agent topic block for conversational ordering
    // + base properties, EXCEPT mandatory/readOnly/hidden (not accepted - TS2353). Scoped catalog client scripts run with
    // `window` = null, so never bridge to the macro through window
})

// Custom variable with label — the same five context properties as CustomVariable.
// `mandatory`, `hidden` and `readOnly` are NOT supported on custom UI component variables.
CustomWithLabelVariable({
    question: '',           // mandatory
    macro: '',              // string | Record<'sys_ui_macro'> | UiMacro, optional (see CustomVariable)
    // summaryMacro, widget, macroponent, topicBlock — as on CustomVariable
    // + base properties, EXCEPT mandatory/readOnly/hidden (not accepted - TS2353)
})
```
