Example - Check The Lookups Value
Example scenario
You are creating an Order and selecting a Customer from a lookup field.
Before saving the record, you want to verify that the selected customer is active.
If the customer is inactive, a warning message is displayed and the record is not saved.
This is useful when you want to prevent users from linking records that should no longer be used.
Step 1: Include the required value in the lookup
In the source table used by the lookup (in this example, the Customers table), make sure the field you want to validate is available in the lookup value.
For example, if the Customers table contains a field such as:
- Active
- internal name:
active
enable Include in lookup selected value for this field in the developer settings.
This allows you to access the value later in JavaScript through the lookup object.
Step 2: Add JavaScript in Before model save
In the target table (in this example, Orders), open the advanced settings and add your JavaScript to Before model save.
We use Before model save because the validation should run only when the user saves the record.
JavaScript example
if (doo.model.customer.value && doo.model.customer.value.active === false) {
doo.alert.showWarning(
'Inactive customer',
'The selected customer is inactive. Please choose another customer.'
);
doo.model.isValid = false;
} else {
doo.model.isValid = true;
}How it works
doo.model.customer.value
represents the selected record in the lookup field.
doo.model.customer.value.active
reads the value of the active field from the selected customer.
doo.model.customer.value.active === false
is the condition that checks whether the selected customer is inactive.
doo.alert.showWarning(...)
displays a pop-up warning message to the user.
doo.model.isValid = false
prevents the record from being saved.
doo.model.isValid = true
allows the record to be saved if the condition is met.
Result
When the user selects an inactive customer and tries to save the order, a warning is shown and the record is not saved.