> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloneable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rules that read a linked object

> Show, require, lock, check, filter or fill a field from the object a record links to, or from the objects that link to it

Field rules and icon rules can read the object a record links to through a [Link field](https://docs.cloneable.ai/guides/forms/link-fields.md), and the objects that link to it. For example: show a field only when the linked plant pole's owner is a given company, or color a pole green when its plant pole matches.

A rule reads one step away. It sees the linked object's own fields, never the objects that object links to.

## What can read a linked object

| Rule | Where you set it | Reads linked objects |
| - | - | - |
| Map icon | Icon builder › **Show when** | Yes |
| Shown | Field › **When it appears** › **Only when…**, or an expression | Yes |
| Required | Field › **When it's required**, a condition or an expression | Yes |
| Editable | Field › **When it's editable** › **Or lock it conditionally**, a condition or an expression. See [Lock a field with a rule](https://docs.cloneable.ai/guides/forms/lock-a-field.md) | Yes |
| Value check | Field › **Checks**, an expression | Yes |
| Allowed options from a dataset | Field › **Options** › **Filter by this record**, an expression | Yes |
| Suggested value | Field › **Auto-fill** › **Expression**, **Suggest** | Yes |
| Calculated value | Field › **Auto-fill** › **Expression**, **Auto**. Cloneable recomputes it on the server (below) | Yes |

A rule gives the same answer whether you build it as a condition or write it as an expression, on the web and on iOS.

## Build a condition on a linked field

In any condition, open the field picker. Below the record's own fields are two more groups:

* **Linked**: the fields of what this record links to, for example "Plant pole ▸ Owner".
* **Linked from**: the fields of objects whose Link field points at this record.

**One linked object.** Pick the linked field, then the operator and the value. When nothing is linked, the condition behaves as on an empty field: *is* is false, *is not* is true, *is empty* is true.

**A list link.** Pick the list, then choose **any linked**, **every linked**, **no linked** or **how many linked**. For the first three, pick the linked field. *Every linked* is false when nothing is linked. **How many linked** compares the number of linked objects, for example "more than 1".

**Any object.** For a field that links to any template, the picker lists every template in the configuration, for example "Anything ▸ Plant pole ▸ Owner". The rule then reads "the linked object is a plant pole and its Owner is …". A linked object of another template doesn't match, and is never an error.

**Linked from.** This is always a list: choose any, every, no or how many, then the field. For example, "any new pole linked to this plant pole has Owner Power Co".

To check a rule before you save it, use **Try it** in the form preview, or **Linked objects** in the icon simulator to link real objects from the job.

## Write an expression

Expressions read `links.<Link field name>` for what the record links to, and `linkedFrom.<template name>` for what links to it. `linkedFrom` is always a list.

```js theme={null}
links.plant_pole?.owner === 'Power Co'                      // one link
links.attachments.some(a => a.kind === 'power')             // a list link
links.attachments.length > 1                                // how many are linked
links.anything?.$template === 'plant_pole'                  // which template an any-object link points at
(linkedFrom.service_drop ?? []).length                      // how many link here
rows.filter(r => !links.plant_pole?.owner || r.owner === links.plant_pole.owner)  // allowed options
```

Use `?.` and `??`. An expression that reads through an empty link without them stops with an error. The rule then fails open, and a calculated value is left empty.

## Calculated values that read a link

A calculated value is stored with its record, so Cloneable keeps it current on the server:

* when the record is saved;
* when an object it links to, or an object that links to it, is saved.

The recomputed value syncs to the web and to phones like any other edit, with history. The server's value wins.

Limits:

* A recompute caused by another object's save doesn't set off further recomputes.
* One save recomputes at most 200 linked records. The rest catch up the next time they are saved.
* A calculated value can't read a linked object's calculated value that is itself calculated from links. Saving the template is refused with a message that names the field.
* If the linked object can't be found (archived, or not loaded), the stored value is kept. Clearing the link recomputes it, usually to empty.

## When something is missing

| Case | What happens |
| - | - |
| Nothing is linked, or the linked object is archived or can't be found | The rule behaves as on an empty field |
| The Link field, or the linked field, was renamed or deleted | The builder shows "Missing: …" with **Remove this condition**. The rule doesn't apply: the field stays shown, not required and editable, and an icon rule falls through to the next icon |
| An expression stops with an error | **Try it** shows the error. In the apps the rule fails open, and a calculated value is empty with the calculation message |

Other rules and icons keep working in every case.

Some places look at one record at a time with no job loaded: the KMZ export, and a record opened on its own page. There, linked reads count as missing, and calculated values keep their stored value.

## Older iOS apps

An iOS app from before linked rules shipped can't read linked objects. On that app, rules that read a link fail open: the field is shown and not required. The server ignores what an old phone writes to a calculated field that reads a link, and keeps its own value. Ask crews to update the app.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.