Skip to content

Commit 2cafa56

Browse files
committed
docs(data-modeling): list percent among the formula return types
The formulas and field-types pages enumerate a formula's returnType; both now name percent and state its fraction convention, its scale and its percentDisplay face, as the field schema's describe does. Claude-Session: https://claude.ai/code/session_01Utp6CajiB6BSQKWowy6YLB Co-authored-by: Claude <noreply@anthropic.com>
1 parent 51faf90 commit 2cafa56

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎content/docs/data-modeling/field-types.mdx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ Calculated field using a CEL expression (see [Expressions](/docs/data-modeling/f
687687
| Property | Type | Default | Description |
688688
|:---|:---|:---|:---|
689689
| `expression` | `string \| Expression` | **required** | CEL calculation expression |
690-
| `returnType` | `'number' \| 'text' \| 'boolean' \| 'date' \| 'currency'` | — | Declared value type of the computed result. `currency`: an amount of money, in the currency the formula's own `currencyConfig` declares (none: dynamic; over record-mode amounts, `record` with their `currencyField`) |
690+
| `returnType` | `'number' \| 'text' \| 'boolean' \| 'date' \| 'currency' \| 'percent'` | — | Declared value type of the computed result. `currency`: an amount of money, in the currency the formula's own `currencyConfig` declares (none: dynamic; over record-mode amounts, `record` with their `currencyField`). `percent`: a ratio, read as a `percent` field reads its stored value — a fraction (`0.25` shows `25%`, so the expression divides and does not multiply by 100) unless the formula declares a `max` above 1, then percentage points; its `scale` is the decimal places of the displayed percentage (absent: 0) and its `percentDisplay` picks the bar or the plain face. Declared, never inferred |
691691

692692
```typescript
693693
{ name: 'total', label: 'Total', type: 'formula', expression: 'record.quantity * record.unit_price', returnType: 'number' }
@@ -697,7 +697,8 @@ Calculated field using a CEL expression (see [Expressions](/docs/data-modeling/f
697697
evaluates the expression. The form and the grid cell draw it by `returnType`: `number` is
698698
formatted as a number field formats it (to the field's `scale`), `boolean` as Yes / No in the
699699
UI language (a non-boolean reads empty), `date` as the date field's absolute face (not the
700-
grid's relative one), and `text` in a monospace font. With no `returnType`, a number is drawn
700+
grid's relative one), `percent` as a percent field draws it (its `scale`, `max` and
701+
`percentDisplay`), and `text` in a monospace font. With no `returnType`, a number is drawn
701702
as a number and anything else as text; nothing is inferred from the expression.
702703

703704
#### `expression` on a stored field

‎content/docs/data-modeling/formulas.mdx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ evaluates (`objectql` computes a formula virtual field from its `expression`
132132
only). Do **not** pass `type: 'currency' | 'number' | …` to `Field.formula` — it
133133
is rejected by the typed `FieldInput` and, untyped, would override `type:'formula'`
134134
so the field silently never computes. To declare what the formula returns, set
135-
**`returnType`** (`'number' | 'text' | 'boolean' | 'date' | 'currency'`). You declare it
135+
**`returnType`** (`'number' | 'text' | 'boolean' | 'date' | 'currency' | 'percent'`). You declare it
136136
yourself — nothing back-fills it — but the agent-callable `validate_expression`
137137
tool reports the type it infers from the expression (`inferredType`) so an AI
138138
author can stamp the matching value. A `'currency'` result is an amount of money
@@ -141,7 +141,13 @@ and carries its currency the way a currency field does: in the formula's own
141141
record-mode amounts it is `{ currencyMode: 'record', currencyField }`, naming the
142142
same code field). Copy it from
143143
the currency field the formula computes from — `inferFormulaReturn` in
144-
`@objectstack/formula` answers both halves for a formula it can prove is money. Consumers read the declared `returnType`
144+
`@objectstack/formula` answers both halves for a formula it can prove is money. A `'percent'`
145+
result is a ratio, read exactly as a `percent` field reads its stored value: a
146+
fraction (`0.25` shows `25%`, so the expression divides and does not multiply by
147+
100), unless the formula declares a `max` above 1, then percentage points. Its
148+
`scale` counts the decimal places of the displayed percentage (absent: 0), and
149+
`percentDisplay` picks the bar or the plain face. No CEL type proves a quotient
150+
is a percentage, so `'percent'` is only ever declared, never inferred. Consumers read the declared `returnType`
145151
instead of re-parsing the expression (record-title eligibility, for one: a
146152
formula is title-eligible only when its `returnType` is `'text'`, which is what
147153
lets it be *derived* as the record title — an explicit `nameField` pointer is

0 commit comments

Comments
 (0)