# Report a run

A station attaches the run's report and any supporting documents to its work record. Both are markdown. For what belongs in each, see [Each output answers one question](/docs/method/run-outputs).

| Call | Attaches | Per work record |
|---|---|---|
| `attachReport(work_record.id, markdown)` | The run report | One. A later call replaces it. |
| `attachDocument(work_record.id, title, markdown)` | A supporting document | Any number. Each call adds one. |

Signatures are in the [lib-factory README](https://github.com/assemblyline-sh/lib-factory#exports).

## Attach the report

Attach the report once, at the end of `execute`, after reporting each workpiece's outcome. Render it from a `report.md` template next to `station.js` ([Write reports from templates](/docs/guides/report-templates)):

```js
await attachWorkpieces(work_record.id, workpieces);
await attachReport(work_record.id, renderLocal(import.meta.url, './report.md', { results }));
```

The full station is in [Write a station that processes workpieces](/docs/guides/process-workpieces).

- **Attach one every run,** including a run with no work. The template should say "No invoices waiting" rather than render nothing: the Orchestrator rejects an empty report.
- **One report per work record.** A later `attachReport` in the same run replaces the earlier one, so call it once.

## Attach a supporting document

```js
const doc = renderLocal(import.meta.url, './totals-check.md', { invoice, lines_total });
await attachDocument(work_record.id, `Totals check: ${invoice.number}`, doc);
```

The title is what a reader sees in the list of documents, so make it say what the document proves, and keep it unique within the run.

## The calls never throw

Each call returns `true` when the Orchestrator accepted it and `false` when it didn't, and logs why. A failed attach doesn't fail the run, so check the return value if the station must not finish without it.

## Read them

- **In the Orchestrator:** open the work record. The report is on its **Report** tab; supporting documents are on **Documents**.
- **From a terminal:**

```bash
al-orc work-records show <work-record-id> --report
al-orc work-records show <work-record-id> --supporting-docs   # lists them, with ids
al-orc supporting-docs show <document-id>
```

## Check them in a local run

`npx factory stations run` gives the station a work record id starting with `local-`. The attach calls then write to the factory's disk and never call the Orchestrator:

```text
temp/work_records/local-wr-…/
├── report.md
├── workpieces.json
└── Totals_check__INV-1001.md     the title, with anything but letters, digits, - and _ made _
```

Open `report.md` to see the report as it will appear. A factory session writes the same copies under `temp/work_records/<work-record-id>/`. Two documents with the same title in one run overwrite each other there, though the Orchestrator keeps both.
