Category trees: records inside records
A table whose records have a parent of their own kind can be shown as a tree, with another table's records hanging underneath, the selected record's form beside it, and a check that stops a branch being moved inside itself.

Chairs are furniture, and furniture is office supplies. Cost centres sit inside departments, and a bill of materials has parts inside parts. When a record's parent is a record of the same kind, a list is the wrong shape. You want a tree.
To follow along, import the Product Categories sample. It comes with the platform's sample solutions and has two tables, Category and Product, and a Product Catalogue app. The sample ships the structure only, so we typed in a small catalogue. Every picture is the real product.
A lookup that points at its own table
A category's parent is another category, so Category has a lookup field, Parent category, that points back at Category itself. Tell the table that this is how its records nest: select the field on the table's Fields and choose Use as parent field. The field is then marked (Parent field):

The button only appears on a lookup that points at the same table. A lookup to a different table doesn't describe nesting.
Make a view into a tree
In the View Designer, set Layout to Tree and press the Tree button beside Filter. The panel says what the tree draws:
- Top level is the view's own table, nested by the parent field. Everything else on the card is optional and comes from the table if you leave it. Here Second line is set to None, because in a tree the parent is already the row above.
- Add a level hangs another table underneath. Here Product hangs under Category, linked by the product's own Category lookup, so each category's products appear inside it.
- When selected, show decides what opens beside the tree: the record's form for records people edit, a read-only card for records people only read, or nothing.
Apply, then save the view.
Using the tree
Open the app and the tree is the page. Click a category and its form opens beside the tree, where you can change it and save:

Products show their SKU as a second line, from the table's secondary text. Click one and its card opens instead of a form, because the view said so:
Search the tree finds a record wherever it is and shows the branch it sits in:
Readers can also focus the tree on one branch, with the crosshair beside the search box, and step back out with the trail above it.
A branch can't move inside itself
What if someone makes Office Supplies a child of Chairs? Chairs is inside Office Supplies, so the tree would loop forever. The save is refused, whichever screen it comes from:

A record can't be its own parent either. Moving a branch somewhere else outside itself is fine, and everything under it moves with it.
What the sample stores
Two documents make the tree. The first is the table, which says which of its lookups is the parent:
{
"logicalName": "par_category",
"displayName": "Category",
"displayCollectionName": "Categories",
"primaryField": "par_name",
"secondaryField": "par_code",
"hierarchyParentField": "par_parentcategory",
"fields": [
{ "logicalName": "par_name", "displayName": "Name", "dataType": "Text", "isRequired": true, "isPrimary": true },
{ "logicalName": "par_code", "displayName": "Code", "dataType": "Text", "maxLength": 20 },
{ "logicalName": "par_parentcategory", "displayName": "Parent category",
"dataType": "Lookup", "targetEntity": "par_category" }
]
}
hierarchyParentField is what Use as parent field sets. It is also what makes the platform check
for loops on every save, so it belongs on the table rather than on a view: a category can't be made
its own ancestor from a form, an import or a script.
The second is the view, which says how to draw it:
{
"logicalName": "par_category_tree",
"displayName": "Category tree",
"entity": "par_category",
"columns": ["par_name", "par_code"],
"hierarchy": {
"nodeTypes": [
{ "id": "category", "entity": "par_category",
"childOf": { "field": "par_parentcategory" }, "secondary": "" },
{ "id": "product", "entity": "par_product",
"childOf": { "field": "par_category", "of": "category" },
"detail": { "kind": "Card", "name": "par_product_card" } }
],
"expandRoots": true,
"rootPicker": true
}
}
Each entry in nodeTypes is one level of the panel you filled in. The category level hangs from its
own parent field. The product level hangs from the product's Category lookup, "of": "category"
saying which level it hangs from. "secondary": "" is the None you chose for the second line, and
detail is the card that opens when a product is selected. expandRoots and rootPicker are the
two ticks at the top of the panel: open the first level when the view loads, and let readers focus on
one branch.
Designing a hierarchy
A tree is a lookup to its own table, but a few choices decide whether it stays easy to live with.
- Top-level records have no parent. Office Supplies is at the top because its Parent category is empty. Don't invent a Root category to hang everything from; an empty parent already means top.
- Keep the parent optional. If the field were required, the first category could never be created, since there would be nothing to choose.
- Put things in the tree, not in the categories. Products are a separate table hanging from the leaves, not categories with a price. That keeps the category table about classification and lets products have their own fields, forms and security.
- Choose a second line that says something new. In the sample, categories show none, because the row above already says what contains them, while products show their SKU from the table's secondary text.
- Decide what opens when somebody selects a node. A form for records people maintain, a read-only card for records they only consult, or nothing for a tree that is only a map.
Reading a tree from a script
A script reads the parent like any other lookup. This server rule, registered before a category is saved, refuses to put a category under one that has been retired, so nothing new is filed in a branch nobody uses any more:
var parentId = getValue('par_parentcategory');
if (!isEmpty(parentId)) {
var parent = getRecord('par_category', parentId);
// State 1 is Inactive, on every table.
if (!isEmpty(parent) && parent.state == 1) {
throwValidationError('That category is no longer used. Choose an active parent.');
}
}
The loop check is the platform's, so the script never has to walk up the tree to look for one. A
rule like this one only has to look one level up. Query records from a script
explains getRecord, and Add a server validation rule
how to register the step.
How deep can it go?
Deeper than any sensible tree. The loop check follows a record's ancestors up to five thousand levels, which is far more than any catalogue or organisation needs; a tree people can read rarely goes past six or seven. Each level is just a lookup, so a deep tree costs nothing extra to store.
The organisation chart is one of these
The platform's own Organisation app is the same mechanism at work: units inside units, with the people of each unit underneath. That tree is more than a picture. Security roles can grant access to my unit and below, so a regional manager sees what their region's teams create and nothing else, and moving a unit in the tree moves who can see what. The Organisation app shows the chart, and Set up your organisation the access it gives.
A tree in a list, too
The tree layout is one way to show a table, not the only one. The same categories can have an ordinary list view as well, with Parent category as a column, which is quicker for editing many records at once or for filtering. A maker can give a table both and let the app's navigation offer each. Views: the lists people work in covers ordinary views.
Four trees worth building
The sample is a product catalogue, but the shape fits a lot of business data. Each of these is one table with a lookup to itself, and often a second table hanging underneath.
| Tree | Parent field | Hanging underneath | What the tree answers |
|---|---|---|---|
| Cost centres | Reports to | Budget lines, from their Cost centre lookup | Which budgets roll up into Facilities? |
| Regions and sites | Part of | Sites, then rooms | Where is room 2.14, and what else is in that building? |
| Parts and assemblies | Used in | Suppliers' prices, from their Part lookup | What goes into this pump, down to the last seal? |
| Document folders | Folder | Documents with a File field | Where is the 2026 insurance certificate filed? |
For parts, notice that a bill of materials often needs a quantity: four bolts in each bracket. A quantity belongs to the link, not to the part, so the honest model is a table in the middle, Part usage, with a lookup to the assembly, a lookup to the component and the quantity, the same shape as the enrolments in Relationships between tables. Use a parent field when each record has one place in the tree; use a table in the middle when the same record appears in several places.
Questions that come up
Can a record have two parents? No. The parent field is a lookup, and a lookup holds one record. If something really belongs in two branches, the table in the middle above is the answer.
Can I move a whole branch? Yes. Change the parent of the branch's top record and save; every record under it moves with it, because each still points at the same parent as before. The loop check only refuses a move into the branch's own inside.
What happens to the children if I delete a parent? The delete is refused while children point at it, as with any lookup. Move the children to another parent, or delete them first. Relationships between tables explains the rule.
How do people find one record in a big tree? With Search the tree, which shows the branch around each match, or by focusing on one branch with the crosshair and working inside it.
What it's good for
The same mechanism draws the platform's own organisation chart, with units inside units and the people of each unit underneath. It's not a special screen for categories. Any table with a parent of its own kind can be a tree: regions, cost centres, folders, parts.
Next: importing records from a spreadsheet, and what happens to the rows that don't fit.