Write expressions
Section titled “Write expressions”This how-to is for builders who want more than the fixed settings offer. An expression is a short JavaScript formula that OSOS works out for you: a calculated field value, a condition that locks or hides a field, a filter value such as “seven days from today”, or a value a reaction writes. This page is the reference: where expressions go, what they can read, every built-in function, the editor that checks them, and recipes you can copy.
You need:
- Developer access to Administration and to the module you are building.
- An entity with a few fields, and their normalized names — expressions refer to fields by normalized name, not by label (see Name a field).
- Basic JavaScript: comparisons,
&&and||, the? :operator, and array methods such asmap,filterandreduce.
For the idea behind pointers and expressions, see Builder concepts.
Where you write expressions
Section titled “Where you write expressions”Every expression box knows where it is. It decides what the expression can read (the record, the event, the user) and which functions are offered. The table lists the main places.
| Where | Setting | What the expression can read |
|---|---|---|
| Field settings | Default Value › Advanced (Type expression) — see Calculated fields cookbook | The record’s fields (value); scope.index for a field inside a repeatable block |
| Field settings | Conditional expression under Lock Field, Hide Field and Required; Min Expression and Max Expression | Same as above |
| Queries and filters | Value source Expression in a condition — see Queries & filters | No record. Only functions such as scope.me() and scope.today() |
| Views | Query parameters › Value type Expression — see Data Views & Faces | No record. The view’s filter-first values (scope.filterFirst) |
| Buttons | Fields Mapping, link tokens, and a system button’s Conditional display — see Buttons | The record, and its record info (scope.entry) |
| Reactions | Action values set to Expression — see Reactions & automation | The record, the event, earlier actions’ outputs |
| Workflows | Step owner Expression, action conditions, and time limits — see Workflows | The record. Step owners and time limits also see record info; step owners see workflow details |
| Aggregate entities | Fields mapping — see Virtual entities | The source record (scope.entry) |
The syntax
Section titled “The syntax”An expression is ordinary JavaScript. Most are one line whose result is the value:
value.unitPrice * value.quantityYou can use the standard JavaScript built-ins — Math, Date, JSON, String,
Number, string and array methods, template literals, optional chaining (?.)
and ??. For longer logic, wrap the steps in a function that you call at once:
(() => { const total = value.total ?? 0; if (total > 1000) { return 'Large'; } return 'Small';})()Two names are always there:
value— the record’s field values, by normalized name. Usevalue.dueDate, orvalue["due-date"]when the name is not a plain identifier.scope— the built-in functions and extra variables, such asscope.me()andscope.index.
How field values look
Section titled “How field values look”| Field type | In value | Example |
|---|---|---|
| Text | a string | value.title?.trim() |
| Number | a number | value.total > 10 |
| Date, Date-time, Time | a date string | new Date(value.due) < new Date() |
| Boolean (switch) | true or false | !value.done |
| Reference or User | { dataEntity, dataEntry } — dataEntry is the record’s id | value.owner?.dataEntry |
| Translated text | an object with one text per language | value.name?.en |
| Multiple or repeatable field | a list | value.tags.includes("vip") |
| Repeatable block | a list of rows; each row has the block’s fields | value.lines.map((l) => l.qty) |
Empty fields are null or missing. Guard them with ?. and ?? — see the
empty values recipe.
Record info: scope.entry
Section titled “Record info: scope.entry”Where the record info is available (buttons, reactions, workflows), the Entry info group of the inspector offers:
| Path | Holds |
|---|---|
scope.entry.id | The record’s id |
scope.entry.creationInfo.doneAt / .doneBy | When and by whom it was created |
scope.entry.updateInfo.doneAt / .doneBy | When and by whom it was last updated |
scope.entry.state | 0 Draft, 1 Active, 2 Archived |
value._metaCurrentSteps | The record’s current workflow steps (entities with a workflow) |
Field settings — calculated values and the lock, hide and required conditions — see only the field values, not the record info.
Built-in functions
Section titled “Built-in functions”Call a function on scope: scope.me(), scope.today(). The editor lists only
the functions that work where you are writing, under Functions.
Available in the table means:
- All — everywhere, including field settings.
- Server — places worked out on the server: queries and filters, query
parameters, reactions, tokens, workflow step owners, aggregates. Not in field
settings. Workflow time limits offer only
me,current_user,isUserAnonymous,isUserAuthenticatedand the date functions. - Data — the data service only: query parameters, tokens, workflow step owners, aggregates. Not in reactions or field settings.
- Browser — settings worked out in the browser: a view’s template parameters, and a button’s Fields Mapping and Conditional display.
People and organization:
| Function | Returns | Available | Example |
|---|---|---|---|
scope.me() | A reference to the current user | All | value.assignee.dataEntry === scope.me().dataEntry |
scope.current_user() | A reference to the current user: {"dataEntity": "USER", "dataEntry": "<id>"}. Empty (null) on the server when nobody is signed in | All | value.assignee.dataEntry === scope.current_user().dataEntry |
scope.myGroups() | A list of references to the groups the current user belongs to | All | scope.myGroups().some(g => g.dataEntry === 'group-1') |
scope.myGroupsUsers() | A list of the users who share a group with the current user | All | scope.myGroupsUsers().length |
scope.myGroupsIds() | A list of the ids of the current user’s groups | Server | scope.myGroupsIds().includes('group-1') |
scope.myCollections() | A list of references to the collections the current user belongs to | Server | scope.myCollections().some(c => c.dataEntry === 'collection-1') |
scope.myCollectionsIds() | A list of the ids of the current user’s collections | Server | scope.myCollectionsIds().length > 0 |
scope.myOrgUnit() | A reference to the current user’s organization unit | All | scope.myOrgUnit().dataEntry === value.orgUnit.dataEntry |
scope.myUsersGroups() | A list of references to the current user’s user groups | All | scope.myUsersGroups().length > 0 |
scope.myOUGroups() | A list of references to the groups of the current user’s organization unit | All | scope.myOUGroups().length > 0 |
scope.myRoles() | A list of references to the current user’s roles | All | scope.myRoles().some(r => r.dataEntry === 'role-1') |
scope.myQueryGroups() | A list of references to the query groups the current user matches | All | scope.myQueryGroups().length > 0 |
scope.isUserAnonymous() | true when nobody is signed in | Server | !scope.isUserAnonymous() |
scope.isUserAuthenticated() | true when someone is signed in | Server | scope.isUserAuthenticated() |
scope.currentSpace() | The space the request runs in | Data | scope.currentSpace() |
scope.thisReference() | A reference to the record being worked out | Browser | scope.thisReference().dataEntry |
Dates — each returns an ISO 8601 date string, in the space’s time zone:
| Function | Returns | Available | Example |
|---|---|---|---|
scope.now(shift?) | The current date and time | All | value.dueDate > scope.now('-1d') |
scope.today(shift?) | Today | All | value.date >= scope.today() |
scope.StartOfDay(shift?) | The start of today | All | value.createdAt >= scope.StartOfDay('-1d') |
scope.StartOfWeek(shift?) | The start of this week | All | scope.StartOfWeek('-1w') |
scope.StartOfMonth(shift?) | The start of this month | All | scope.StartOfMonth('-1M') |
scope.StartOfYear(shift?) | The start of this year | All | scope.StartOfYear() |
The optional shift moves the date. Write a sign, a number and a unit, in
quotes: '-1d', '+2w', '-1M', '+1y', '-10m'. Units: d days, w weeks,
M months, y years, h hours, m minutes, s seconds.
More variables
Section titled “More variables”These appear under Variables in the inspector, only where they apply:
| Variable | Holds | Where |
|---|---|---|
scope.index | The row number in a repeatable block (0 is the first row) | A field inside a repeatable block; reaction actions that create or update a block row |
scope.entity | The entity: id, normalizedName, name | Buttons’ tokens |
scope.filterFirst | The values chosen in the view’s filter-first step; undefined when there is none | View query parameters |
scope.totalCount() / scope.entries() | The list’s total count, and its loaded records | Expressions on a whole list, where value is the list |
scope.currentUser, scope.currentStepId, scope.history, scope.workflow, scope.dataEntity | The user moving the record (an id), the step it leaves, its workflow history and definitions | Workflow step owner expressions |
Pointers: the @ form
Section titled “Pointers: the @ form”Each function also has a pointer form: @me, @myGroups, @today,
@StartOfMonth. You pick pointers from the Pointer value source of a query
condition, without writing an expression — see
Queries & filters. Inside an expression, write
the scope. form: @me is scope.me().
What an expression must return
Section titled “What an expression must return”The result must have the shape the field stores:
| Field type | Return | Example |
|---|---|---|
| Text | A string | `${value.code}-${value.year}` |
| Number | A number — 10, not '10' | Math.round(value.total * 100) / 100 |
| Date | A date string or a Date; stored as yyyy-MM-dd | new Date(Date.now() + 7 * 86400000) |
| Date-time | A date-time string or a Date | scope.now() |
| Boolean, and every condition | true or false | value.total > 1000 |
| Reference or User | { dataEntity, dataEntry }, or a list of them for a multiple field | scope.me() |
A result of the wrong kind is rejected: in a calculated field, the form marks the field as invalid. On save, the server rejects both a wrong and an empty result; a locked field then keeps its previous value, or stays empty on a new record.
In a query or filter, the Expression value is compared as is, with no conversion. The editor checks the result against the field and, if it does not fit, shows this warning: This field expects {expected}; a different result matches no entries. You can still select Apply, but the condition will match nothing. The exact shapes per field type are in Criteria and field-path dialects.
Use the expression editor and inspector Since 1.10
Section titled “Use the expression editor and inspector Since 1.10”Every expression box is a small code editor. As you type it suggests field paths and functions, with a description of each, and it underlines problems.
Next to the box are two buttons:
- Open editor — opens the large Expression editor dialog.
- Open expression inspector — opens the Expression context panel beside the form.
The expression editor
Section titled “The expression editor”- Select Open editor next to an expression box.
- Write the expression on the left. Suggestions appear as you type; hover a name to read its description.
- To insert a field or function, find it in the Expression context panel on the right and click it (or select it and press Enter). Its path is inserted at the cursor.
- Read the status at the bottom left: No problems, or a count of error(s) and warning(s). Errors are mistakes in the JavaScript itself, such as a missing bracket. Warnings flag a name the editor does not know, or a result of the wrong type.
- Select Apply (or press Ctrl+Enter, Cmd+Enter on a Mac) to copy the expression back to the box, or Cancel to discard it.
Apply is never blocked by errors or warnings. Read them before you apply. If the code editor cannot load, the box says The code editor could not load. Editing as plain text. and you can still type.
The expression inspector
Section titled “The expression inspector”The Expression context panel shows everything the expression can read, in groups:
| Group | Holds |
|---|---|
| The entity’s name (or Current entry) | The record’s fields, with blocks and their inner fields |
| Entry info | Record info: id, created, last updated, state, workflow steps |
| Event | What triggered a reaction |
| Action outputs | Results of earlier actions in the same reaction |
| Sources | Other records the reaction or aggregate reads |
| Variables | Extra values such as scope.index and scope.filterFirst |
| Functions | The built-in functions that work here |
- Select Open expression inspector next to an expression box.
- Type in Search name or path… to filter the tree by label or path.
- Select an item. The bottom of the panel shows its label, its type (for example
number,date,reference,list<string>), its full Path, and — for functions — Parameters, a description and an Example. - Copy the path with Copy path, double-click the item, or press Enter. Paste it into the expression.
If the panel says No context available for this field, there is nothing to list for this box.
Recipes
Section titled “Recipes”Only records I created
Section titled “Only records I created”In a query condition: field Created by, operator equals, value source Expression:
scope.me()The same as the @me pointer. Each person sees only their own records.
Due within the next 7 days
Section titled “Due within the next 7 days”Two conditions on Due date, under All conditions are met — greater than or equal to:
scope.today()and less than or equal to:
scope.today('+7d')The filter moves with the calendar; nobody has to edit it.
Records of my groups
Section titled “Records of my groups”On a reference field that points to groups (for example Team), operator In:
scope.myGroups()A list matches when the record’s group is any of the current user’s groups. Use
scope.myOrgUnit() with equals for “my department”.
Require a field only when it is mine
Section titled “Require a field only when it is mine”In Required › Conditional expression of a field:
value.assignee?.dataEntry === scope.me().dataEntryThe field is required only for the person the record is assigned to.
Combine conditions
Section titled “Combine conditions”In Hide Field › Conditional expression:
value.amount > 1000 && (value.urgent || value.priority === 'High')&& means both, || means either. Use brackets to group, as you would in
arithmetic.
Handle empty values
Section titled “Handle empty values”(value.discount ?? 0) + (value.fee ?? 0)value.owner?.dataEntry ?? null(value.lines ?? []).length?? gives a fallback when a field is empty. ?. stops at an empty reference
instead of failing. Without them, one empty field makes the whole expression fail.
Date arithmetic
Section titled “Date arithmetic”Days between two dates (a Number field):
value.start && value.end ? Math.round((new Date(value.end) - new Date(value.start)) / 86400000) : nullDays overdue (a Number field):
value.dueDate ? Math.max(0, Math.floor((Date.now() - new Date(value.dueDate)) / 86400000)) : 086400000 is the number of milliseconds in a day. Subtracting two dates gives
milliseconds.
Text from several fields
Section titled “Text from several fields”`${value.code ?? ''}-${new Date().getFullYear()}`A template literal (between backticks) always gives a string, which a Text field needs.
See also
Section titled “See also”- Calculated fields cookbook — triggers, scopes and recipes for fields that work out their own value.
- Settings every field shares — default values, lock, hide and required.
- Queries & filters — value sources, pointers and parameters.
- Filtering, sorting and search — expression values in the end-user filter.
- Run JavaScript on forms and lists — scripts that react to what people do.
- Builder concepts — pointers and expressions in brief.
Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27