# Instructions for Fluent Field Styles (`sys_ui_style`)

Always reference the Field Style specification for more details.

1. Field styles have **no dedicated constructor**. Author them with the generic `Record()` API and `table: 'sys_ui_style'` — support for that table is new in SDK v4.11.0. Import `Record` from `@servicenow/sdk/core`. Do not look for a `FieldStyle()` function; it does not exist.
2. Every record needs a unique `$id`, plus `name` (the table) and `element` (the field on that table). `element` is declared `dependent: 'name'` in the schema — it is a field name scoped to that table, not a free label.
3. **One record styles one field at one trigger value.** A red/amber/green scheme across three states is three `Record()` calls that differ only in `value` and `style`. Do not try to express several states in one record.
4. **Understand `value` before writing anything — an empty `value` does not mean "always".** A static value applies in **list view only** when the field equals it. A `javascript:` expression applies in **list view only** when it returns true. An **empty** `value` applies **unconditionally in form view**, but in list view only where the field's own value is null/empty.
5. Therefore, for a style that must apply to **every list row** — the normal case for `width` and `text-align` — use the always-true idiom `value: 'javascript:1==1;'`. Leaving `value` empty is the classic mistake here: the width silently applies only to blank cells. Note `value: ''` serializes to `<value/>` and imports back as `null`.
6. `value` supports only **one** `javascript:` entry. Combine multiple conditions into a single expression (`'javascript:current.state == "Completed" && current.error_tables > 0'`) rather than adding a second entry or a second record for the same value.
7. **Do not assume `style` is only for `background-color`.** Any standard CSS property is valid — `font-weight`, `font-style`, `color`, `font-size`, `text-decoration`, `text-align`, `width`, `border`. Style text without touching the background when that is what was asked for.
8. Pair `style` with `themed_style` whenever the style carries colour, so Polaris-themed instances render correctly. Use `--now-color_*` design tokens in `themed_style` and keep a literal fallback in `style`. This technique does **not** work for the reserved `work_notes`/`comments` fields (see item 12).
9. Set `alt` whenever the style conveys meaning visually — above all when `style` sets a `background-image` icon. Without it the indicator is invisible to screen-reader users.
10. **Know the two rendering limits, because the build will not warn you.** On Polaris / Next Experience a `background-color` renders as a coloured **dot indicator** beside the value rather than filling the cell (`font-weight`, `text-align`, `width` are unaffected). And **choice-type fields on forms** (e.g. State) are never background-coloured by `sys_ui_style` — styles on them render in list views only. Do not promise a filled cell or a coloured form choice field.
11. Respect the scope rule: a field style may only target a table or database view in the **same scope** as the style, or a table with at least one field in that scope. A style authored for a table does **not** apply to a database view that includes that table — author a separate record for the view.
12. **`work_notes` and `comments` are a special case and cannot be styled this way.** Those two reserved `task` fields are not styled by `sys_ui_style` at all; only their activity-stream background colour can change, and only through the global-scope properties `glide.ui.activity_stream.style.work_notes` and `glide.ui.activity_stream.style.comments`, set with `Property()` or `Record({ table: 'sys_properties' })` in **global scope**. Any *custom* journal field (e.g. `internal_notes`) is unaffected — style it like any other field.
13. When the target field is **read-only**, the `value` condition governs **both** list and form views, not just the list. Take that into account before concluding a style will not show on a form.
14. Prefer a field style over a client script for purely presentational, value-driven colour or layout. Reach for `UiPolicy`/`ClientScript` only when behaviour (visibility, mandatory, read-only) changes — not appearance.
