Path | Duration | Level | Before you start | |
🔵 Configurator · Level 1 | 50 min | Intermediate | [[06 · Información repetida - Tablas y Subformularios | Repeated information - Tables and Subforms]] |
A good form only asks for what's needed at each moment and does the math for the user. Rules are the tool for achieving this: they change the form while it's being filled in, according to what the user enters.
🎯 By the end you'll know
How to build a rule with its condition (When) and its action (This will happen).
How to show, hide, enable or require fields dynamically.
How to calculate values with formulas and scripts (advanced functions).
How to tell when to use a rule and when an event.
🧠 The idea: When this, this other thing will happen
Every rule has two parts:
WHEN Result is equal to NOT OK THIS WILL HAPPEN Show Corrective action · Mark as required Corrective action
When: a field, an operator and a value. The operators depend on the field type: is empty, is equal to, contains, greater than, is equal to another field, value changes… You can combine several conditions with And (all) or Or (any).
This will happen: one or more actions on fields or blocks: show, hide, enable, disable, mark or unmark as required, change a value, calculate with a formula, run a script or launch a query.
Rule or event?
Rule | Event | |
When it acts | While being filled in | When saved |
What it acts on | The form itself | What happens afterwards: alert, change status, schedule… |
Example | If NOT OK → show Corrective action | If NOT OK → send an email to Quality |
💡 Keep rules simple. Several short rules with a clear name are much easier to maintain than one giant rule with ten conditions.
🛠️ Guided practice
Rule 1 · Ask for explanations only if the control is NOT OK
In lesson 5 you left Rejection reason and Corrective action hidden. Now you'll make them appear when they're needed.
In the Form Builder open the Rules tab and click Add rule.
When:
Resultadois equal toNOT OK.This will happen:
Show
motivo_rechazoand mark it as required.Show
accion_correctoraand mark it as required.
Save and preview: mark NOT OK and then switch to OK.
⚠️ Check what happens when you go back to OK. If the fields remain visible or required, create a second rule with the inverse condition (Resultado is equal to OK → hide and unmark as required).
Rule 2 · Calculate the expiry date with a script
Add two fields to the form:
Shelf life (days) · Numeric · ID
vida_util· default value365.Expiry date · Date · ID
fecha_caducidad· Disabled (it's calculated, not typed).
Create a rule: When
fecha_envasadois not empty.This will happen: on
fecha_caducidad, choose the Script action. In the value type@to see the available functions and chooseaddValueDate. Use{to insert the fields:
addValueDate({fecha_envasado}, {vida_util}, "days")
addValueDate adds an amount of time to a date (days, weeks, months, hours…). If the amount is negative, it subtracts it.
Rule 3 · A numeric formula
Add a field Maximum allowed temperature (Numeric, temp_max, disabled, default value 4) and a field Margin (°C) (Numeric, margen, disabled). Create a rule that calculates the margin with the Formula action:
{temp_max} - {temperatura}
A negative margin indicates that the temperature is above the limit. Formulas work like those in Excel: they support parentheses, powers, rounding, maximums and minimums, among other functions.
🔍 Check that it works
With OK, Rejection reason and Corrective action don't appear; with NOT OK they appear and are required: you can't save without filling them in.
When you set the packaging date to 01/01 with a 365-day shelf life, the expiry is 01/01 of the following year.
With 5 °C, the margin comes out as −1.
⚠️ Common mistakes
"The script does nothing." Functions must start with
@and fields are inserted with{. Also check that the target field is the type the function returns (a date foraddValueDate).Hiding a field in the form expecting it to disappear from the history. They're different things: what's shown in the history is configured in Summary (lesson 8).
Using a rule to send alerts. Rules alert no one; that's what events are for (lesson 9).
Chaining too many conditions in a single rule. If you can't explain the rule in one sentence, split it.
🏋️ Challenge
Make it so that, if temperatura is greater than temp_max, the resultado field automatically switches to NOT OK and becomes disabled, so the operator can't mark it as OK. Hint: the compare with another field operator saves you from typing the 4 by hand. Will the fields from rule 1 also be shown?
📚 Learn more
➡️ Next lesson: After saving - history, mobile and PDF
