# Instructions for Fluent Catalog Variable API
Always reference the Catalog Variable API specification for more details.
1. Variable functions are used as values in the `variables` object of a `VariableSet` or `CatalogItem`. The object key becomes the variable's internal name, used in `g_form` calls and `producer.varName` scripts.
2. `question` is the only property that is mandatory across all variable types. It is the label/question text shown to the user on the form.
3. `mandatory`, `hidden`, and `readOnly` are mutually exclusive constraints — a variable cannot be both `mandatory: true` and `hidden: true` (or `readOnly: true`). Doing so causes a build error.
4. Use `ReferenceVariable` (not `SelectBoxVariable`) when the choices come from another table. `ReferenceVariable` requires `referenceTable` and supports filter qualifiers. Use `LookupSelectBoxVariable` for a reference field displayed as a dropdown.
5. For `ReferenceVariable`, use `referenceQualCondition` for simple encoded query filters (e.g., `'active=true'`), `dynamicRefQual` for a `sys_filter_option_dynamic` reference, and `referenceQual` for advanced script-based qualifiers.
6. Layout variables (`ContainerStartVariable`, `ContainerSplitVariable`, `ContainerEndVariable`, `BreakVariable`, `LabelVariable`, `RichTextLabelVariable`, `HtmlVariable`) do not collect user input — they control form presentation only.
7. `ContainerStartVariable` must always have a matching `ContainerEndVariable` with higher `order` value. Use `ContainerSplitVariable` to create sections within a container.
8. Variable display `order` values should be spaced (100, 200, 300...) to allow inserting variables between existing ones without renumbering.
9. `mapToField: true` with a `field` value automatically maps the variable's value to a specific field on the target record — useful in Record Producers to avoid manual mapping in the `script` property.
10. `width` controls how much horizontal space the variable occupies: 25%, 50%, 75%, or 100% (default). Use narrower widths in two-column layouts.
11. To auto-populate a variable from another variable's referenced record, set all three dynamic-default properties together: `useDynamicDefault: true`, `dependentQuestion` (the source variable), and `dotWalkPath` (the field path on the source record, e.g. `'manager'` or `'department.name'`). The source variable must be a `RequestedForVariable` or `ReferenceVariable` — it needs a referenced record to dot-walk from — and must be declared before this variable in the `variables` object.
12. `dependentQuestion` is a dynamic *default value* only. It does not control visibility and does not filter options: use `CatalogUiPolicy` to show/hide a variable and a reference qualifier (`referenceQualCondition`, `dynamicRefQual`, or `referenceQual`) to filter a reference variable's options.
13. Prefer the source variable's key name as a string for `dependentQuestion` (e.g. `dependentQuestion: 'requestedFor'`). As of SDK v4.10.1 the type also accepts a `ReferenceVariable` / `RequestedForVariable` object, but the only supported object form is a VariableSet dot-walk (e.g. `employeeSet.variables.requestedFor`); passing a variable's own const (e.g. `dependentQuestion: requestedForVar`) type-checks but is not supported. `dependentQuestion` is declared on the shared base config, so every variable type accepts it.
14. **SDK v4.13.0** — every variable type accepts `$meta` with `installMethod` (`'once'` or `'first install'`; `'demo'` type-checks too), so a single variable can load on a different schedule from the rest of the item. A variable is application metadata, not demo data. Do not use `'demo'` on it: demo data is only for rows of tables that do not extend `sys_metadata` (demo-data-guide, SDK v4.14.2).
15. **SDK v4.14.0 — custom UI component variables.** `CustomVariable` and `CustomWithLabelVariable` render through `macro` (Platform UI), `summaryMacro` (summary pages), `widget` (Service Portal), `macroponent` (Next Experience) and `topicBlock` (Virtual Agent). Set one for every context the item is ordered in — none is required or diagnosed, but a variable with none set renders blank. `macro` / `summaryMacro` now accept a `UiMacro()` object and `widget` an `SPWidget()` object from the same project, so define the macro or widget in Fluent and pass the returned value instead of a sys_id. Scoped catalog client scripts run with `window` as null, so never bridge between the macro and a client script through `window`.
