A document template can follow the links stored on a record, forwards: an invoice's partyId opens the party, and the
party's own links one step further. It cannot go the other way. A party stores nothing about its addresses; each address
stores the party. The template language has no search, so to print records that point at a record you declare them
first. A declared related record has a name, and the template prints it like any other field.
Declaring one
In Setup › PDF Documents, open the layout, then Settings › Related Records. Each one is chosen from lists the kernel offers, so only what can work is offered:
| Choice | Meaning |
|---|---|
| Label | Its name in Setup and in the designer's field list |
| Hangs Off | Where it starts: the document itself, or a record the document links to (the invoice's party) |
| Records Of | A stored model that has a link field pointing back at the place it hangs off |
| Linked By | The field of that model that points back (an address's party) |
| Show | The first match (one record, or nothing) or a list (up to 50) |
| Only When | Conditions that must all hold: a field equals, is not, is any of, or (yes/no) is yes or no |
| Sorted By | A field, lowest or highest first. The order they were made when empty |
Through the API it is the template's related list, set with PUT /api/admin/template-layouts/:key/settings or in the
template's own define body:
{
"related": [
{ "key": "billing", "label": "Billing Address", "model": "partners.address", "link": "party", "on": "partyId",
"pick": "first", "where": [{ "field": "isDefault", "operator": "is_true" }, { "field": "kind", "operator": "eq", "value": "billing" }] },
{ "key": "addresses", "label": "Addresses", "model": "partners.address", "link": "party", "on": "partyId",
"pick": "all", "limit": 5, "sort": { "field": "city", "dir": "asc" } }
]
}
on is a lookup field of the document (partyId), or null for records that point at the document itself. The operators
are eq, neq, in, is_true and is_false.
Printing it
The name goes where the record's fields would:
{{record.partyId.billing.line1}}, {{record.partyId.billing.city}}
{{#each record.partyId.addresses}}{{city}} {{kind | label}}{{else}}No addresses{{/each}}
With on: null the path is record.<name>. A first match with no record, or a document whose lookup is empty, prints
empty; a list prints its {{else}} part. A lookup field of a related record prints as { id, label }, like any lookup.
Rules
- Read as the person printing. Only a model they can reach, only the records their companies and role let them read, only the fields they may read. A condition on a field they may not read matches nothing, so a condition can never show what field access hides.
- Only what the template prints is read, at most 10 related records per document, each at most 50 records.
- Checked when it is saved. The model must be stored (a connector-backed model has nothing to search), the link must
be a lookup back to the place it hangs off,
ona lookup of the document, conditions and sort must name fields of that model, and the name can't be a field the record already has, orid,label,name,createdAt,updatedAt. A template that does not pass is refused with every problem listed. - An issued copy keeps them. The declaration is part of what the output pins (and of the template's hash), so a re-print of an issued document reads the same related records the first print did.
- A template without related records is stored, exported and hashed exactly as before.