Block a save with a validation function
Section titled “Block a save with a validation function”This how-to is for builders and the developers who work with them. Some rules are too involved for a field’s own settings — “the end date must be after the start date, unless the request is open-ended”, “a reference number must pass a check-digit test”. A validator function checks the record on the server before it is saved, and stops the save with your own message when the rule fails.
You will write the function, attach it to an entity (to check the whole record) or to a field (to check one value), and give each failure a message people understand.
You need:
- The system Admin level, to add functions. See Functions: run your own code.
- Developer access on the module, to attach the validator to the entity or field.
- A developer who can build a small TypeScript function, or a function your team already has.
Two kinds of validator
Section titled “Two kinds of validator”| Kind | What it checks | When it runs | Attached on |
|---|---|---|---|
| Standalone Validator | The whole record, and the version before the change | Before Save (a new record), Before Edit (a change) or Before Archive | The entity’s Form Settings |
| Value Validator | One field’s value | On Save — when a record is created or changed | The field’s Field Settings |
Both run on the server, so they apply however the record is saved — from a form, a reaction or the HTTP API.
Step 1: Write the function
Section titled “Step 1: Write the function”The platform calls your function with the record, and reads its answer from
result. Return success: true at the top level whenever your function ran, and
put the verdict inside result:
| Your rule | Return |
|---|---|
| Passes | { "success": true, "result": { "success": true } } |
| Fails | { "success": true, "result": { "success": false, "errors": [{ "errorCode": "END_BEFORE_START" }] } } |
A standalone validator
Section titled “A standalone validator”The function receives dataEntry — the record as it will be saved — and, on
Before Edit, existingEntry, the record before the change. Field values are
under value, by the field’s system name.
import { Context } from 'faas-js-runtime';
const handle = async (context: Context) => { const body = (context.body ?? {}) as any; const { dataEntry, existingEntry } = body.data ?? body; const v = dataEntry?.value ?? {};
const errors: { errorCode: string }[] = [];
if (v.start_date && v.end_date && new Date(v.end_date) < new Date(v.start_date)) { errors.push({ errorCode: 'END_BEFORE_START' }); }
// On an edit, refuse to lower the approved amount. const before = existingEntry?.value?.approved_amount; if (before != null && Number(v.approved_amount) < Number(before)) { errors.push({ errorCode: 'AMOUNT_LOWERED' }); }
return { success: true, result: errors.length ? { success: false, errors } : { success: true }, };};
export { handle };On Before Archive the function receives only dataEntry: the record being
archived.
A value validator
Section titled “A value validator”The function receives { value } — just the field’s value. For a field that holds
several values, it is called once for each value. An empty value is not sent to it.
import { Context } from 'faas-js-runtime';
// A reference number: 8 digits, the last one a check digit.const handle = async (context: Context) => { const body = (context.body ?? {}) as any; const { value } = body.data ?? body; const digits = String(value ?? '');
const valid = /^\d{8}$/.test(digits) && [...digits.slice(0, 7)].reduce((sum, d) => sum + Number(d), 0) % 10 === Number(digits[7]);
return { success: true, result: valid ? { success: true } : { success: false, errors: [{ errorCode: 'BAD_CHECK_DIGIT' }] }, };};
export { handle };Build, try and package the function as described in Write a function.
Step 2: Add the function to the entity
Section titled “Step 2: Add the function to the entity”A standalone validator runs only for the entity it belongs to, so add it from that entity:
- Open Administration › Applications › Modules, open the module, and open the entity — for example Leave requests.
- Select the Functions tab, then New Function (Add Function when the list is empty).
- Enter a Name, and choose the Type: Standalone Validator or Value Validator.
- Upload the ZIP and save. Wait until the status is Provisioned — see Add the function.
- Under Errors, add one row for each code your function returns: the Error
Code exactly as the function returns it — for example
END_BEFORE_START— and the Error Message people see, in each language.
| Error Code | Error Message |
|---|---|
END_BEFORE_START | The end date must be on or after the start date. |
AMOUNT_LOWERED | The approved amount cannot be lowered. |
BAD_CHECK_DIGIT | This reference number is not valid. Check the last digit. |
Step 3: Attach it
Section titled “Step 3: Attach it”Check the whole record: a standalone validator
Section titled “Check the whole record: a standalone validator”- In the entity’s designer, open the Structure tab.
- Select the settings icon to open Form Settings.
- Open Standalone Validator and select Add Standalone Validator.
- Enter a Name, choose the function in Standalone Function, and choose when it runs in Standalone Trigger: Before Save, Before Edit or Before Archive.
- Leave Activated on, and save.
Each validator in the list has a switch to turn it off without deleting it, and an Edit button. To check both new records and changes, add the function twice: once with Before Save and once with Before Edit.
Check one field: a value validator
Section titled “Check one field: a value validator”- On the Structure tab, select the field’s settings icon to open Field Settings.
- Find Value Validators. Pick existing validators in Select Value Validators, or select Add Value Validator to create one: a Name, the function in Value Function, and On Save in Value Trigger.
- Save the field, then save the entity.
A value validator is reusable: attach the same one to every field that holds the same kind of value. Value Validators is not offered on blocks, virtual fields or display-only fields.
What people see
Section titled “What people see”When a validator fails, the record is not saved and the person sees the Error Message you entered for each code — in a message on the form, and, for a value validator, next to the field it checked. A code with no row under Errors is reported with no text, so add every code.
How several validators combine:
- Standalone validators run one after another. The first one that fails stops the check, and only its errors are shown.
- Value validators are checked field by field. Each field shows the errors of its first failing validator, and errors from different fields are shown together.
- A validator whose Activated switch is off is skipped.
Check the result
Section titled “Check the result”- Open the entity’s form and enter values that break the rule — an end date before the start date.
- Save. The record is not saved, and your message appears.
- Correct the value and save again. The record is saved.
- If you attached Before Edit, open an existing record and repeat.
Troubleshooting
Section titled “Troubleshooting”| Problem | What to check |
|---|---|
| The save goes through although the rule fails | The function is not Provisioned or not active, or the validator’s Activated switch is off. A validator whose function is not ready is skipped. |
| A standalone validator never runs | The function was added from another entity, or at system or module level. Add it from the entity’s Functions tab. |
| The save fails with a technical error, not your message | Your function returned a top-level success: false, did not answer with JSON, or crashed. Return success: true and put the verdict in result. |
| The message is empty | The code the function returns has no matching Error Code row, or differs in spelling or case. |
| A rule on a new record does not run on edits | Before Save covers new records only. Add the validator again with Before Edit. |
| Restoring an archived record skips the rule | Validators do not run when a record is restored. |
See also
Section titled “See also”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