# Instructions for Fluent ATF List / Related List API

Always reference the `atf` instructions (`get_fluent_knowledge` kind `instruct`) and the ATF List API specification for details.

1. Start from the shared `Test()` scaffold in the `atf` instructions (`get_fluent_knowledge` kind `instruct`). Reach these steps as `atf.list.*` on the callback's `atf` argument; there is no separate import.
2. Use only List ATF step APIs documented in this metadata spec. Give every step a unique `$id` and keep step order deterministic.
3. **Only author `atf.list` steps when something actually drives the list's behavior.** Related lists are ubiquitous by default (Attachments, Approvals, Journal Entries, and any list arising purely from a reference field). A test is warranted when a client script (`sys_script_client`), a UI policy (`sys_ui_policy` with `run_scripts = true`), or a relationship this app defines (`sys_relationship`) affects that related list's visibility, membership, or filtering — not for default platform behavior.
4. **Determine that by checking, not assuming.** Query `sys_script_client`, `sys_ui_policy`, and `sys_relationship` for the target table before concluding a related list has no logic behind it. Match on whether the content actually touches list/related-list behavior; do not filter by author, scope, or age — driving logic lives in Global scope as often as in the app's own scope. When writing the encoded query, note that ServiceNow's `^OR` does **not** distribute an earlier `^AND` term across the whole chain: `run_scripts=true^script_trueLIKEx^ORscript_falseLIKEx` silently lets `run_scripts=false` records back in through the second branch. Split the query or filter the results instead.
5. **`relatedList` values are not guessable and cannot be inferred from types.** They are generated per-table by the platform in the format `<child_table>.<field>` (e.g. `task.parent`, `task_ci.task`) — never `<table>_<table>` — and relationship-based lists appear as `REL:<sys_id>`. Look up the real values for a table before authoring, by running this in **Global scope** against the instance: `var lists = new ATFRelatedListUtil().getRelatedLists('incident'); for (var i in lists) gs.info(lists[i].label + ' => ' + lists[i].value);`
6. Keep `table` and `relatedListTable` straight: `table` is the table whose form or list view is open, while `relatedListTable` is the table the list's **records** live in. `recordId` and `applyFilterToList`'s `first_record` output are typed against `relatedListTable`, not `table`. `relatedListVisibility` takes neither `listType` nor `relatedList`; `listUIActionVisibility` is the only step where `relatedListTable` is optional.
7. Respect the sequencing: a valid form (or list module) must already be open, so precede these steps with `atf.form.openExistingRecord` or equivalent. Use `applyFilterToList` to narrow to a record, then feed its `first_record` output into `recordPresentInList` / `openRecordInList` / `clickListUIAction`. Capture the return value in a `const` only when a later step consumes it.
8. Map the logic you found to the **best-fit** method rather than a default: a hide/show branch → `relatedListVisibility`; logic that filters or narrows records → `applyFilterToList`; logic gating a list UI Action → `listUIActionVisibility` / `clickListUIAction`. Cover every distinct branch of the found logic, including both sides of an `if`.
9. Once `atf.list` is warranted for a list, consider all five **read-only** methods against it — visibility, filtering, membership, navigation, and list UI Action visibility are each meaningful without extra logic. Use `atf.server.recordInsert` to create prerequisite child records if the table has none. Treat `clickListUIAction` differently: it genuinely executes the action, so add it only when the action's behavior itself needs verifying, and place no further steps against that form or list afterwards because it will likely navigate away.
10. When the found logic populates or restricts what the list shows, prefer asserting the underlying data with `atf.server.recordValidation`. Reach for `atf.list` when the list-level **UI** behavior — visibility, filtering, list UI Actions — is what needs verifying.
11. Do not guess sys_ids. Look the list UI Action's sys_id up on the instance (e.g. with this server's query_fluent_records tool on `sys_ui_action`) and pass `Now.ref('sys_ui_action', '<sys_id>')`, and remember the action must exist on the **child** table.
12. These steps validate correctly through build and install, but the SDK notes its own `atf.list` example is **not yet runtime-confirmed** in the ATF test runner. Treat a successful build as shape validation, and verify the test actually passes on an instance before relying on it.
