Domain tables
A domain table is an ordinary table used as a lookup. When an attribute points at a domain table, the records in that table become the only valid values for the attribute.
This is how you get referential integrity without writing a single validation rule.
Why a reference table is required
Section titled “Why a reference table is required”A lookup is only useful if the person choosing a value can recognise what they are choosing.
The picker shows the target record’s identifier and display name (named Code and
Name by default):
SEK - Swedish kronaEUR - EuroUSD - US dollarOn a standard table, the identifier is machine-generated and means nothing to a person. So only reference tables appear in the domain table selector.
A worked example
Section titled “A worked example”Create a Currency table, turn on Use this as a reference table, and add no extra
attributes at all:
| Code | Name |
|---|---|
SEK |
Swedish krona |
EUR |
Euro |
USD |
US dollar |
GBP |
Pound sterling |
Now, on your Accounts table, create an attribute called currency and point it at
Currency. Users filling in an account get a searchable picker instead of a free-text box,
and a misspelled SEK with a trailing space becomes impossible.
Parent-child hierarchies
Section titled “Parent-child hierarchies”A domain table can reference itself. For example, an OrgUnit table can have an optional
parent attribute that also points to OrgUnit. Each row can then point to another row in
the same table to represent its parent. This is a regular domain reference; it does not
automatically enforce tree rules such as preventing cycles.
What is actually stored
Section titled “What is actually stored”When a user picks SEK - Swedish krona, Grunddata stores the source_id of that
currency record — not the text.
This has two consequences worth understanding:
Setting it up
Section titled “Setting it up”-
Create the lookup table and turn on Use this as a reference table.
-
Add its records. The identifier and display name columns are mandatory; add attributes only if the lookup carries extra information.
-
On the referencing table, create an attribute and choose the domain table model and the domain table. The datatype becomes read-only.
-
Save. The attribute now renders as a searchable picker.
Cascading domain attributes
Section titled “Cascading domain attributes”When a lookup is large, filter it by another selection on the same row. Tick Cascade domain values from another domain attribute on the child attribute and choose the cascade parent attribute.
country = Sweden ↓ filtersregion = only Swedish regions offered ↓ filtersbranch = only branches in the chosen regionBoth the parent and the child must be domain attributes on the same table.
Domain values in views and OData
Section titled “Domain values in views and OData”A domain attribute is not exposed as a single field over OData. Instead a view can publish up to three separate fields for it:
| View field | Contains |
|---|---|
{Attribute}SourceId |
The referenced record’s source_id |
{Attribute}Code |
The referenced record’s Code |
{Attribute}Name |
The referenced record’s Name |
For example, a Counterparty domain attribute becomes CounterpartySourceId,
CounterpartyCode and CounterpartyName.
Common domain tables to create first
Section titled “Common domain tables to create first”| Table | Typical codes |
|---|---|
Currency |
SEK, EUR, USD |
Country |
ISO 3166 codes |
Counterparty |
LEI codes or internal counterparty codes |
CostCentre |
Internal cost centre codes |
AccountType |
NOM, MTM, INT |