Back
validateOnUpdate()
Registers one or more validation methods that will be executed only when an existing object is being updated in the database. This allows you to enforce rules that apply strictly to updates, without affecting the creation of new records. You can also control whether the validation runs using the condition and unless arguments.
1. Basic usage: validate existing objects before update
function config() {
validateOnUpdate("checkPhoneNumber");
}
function checkPhoneNumber() {
// Ensure area code is '614'
return Left(this.phoneNumber, 3) == "614";
}
2. Register multiple methods for validation on update
function config() {
validateOnUpdate("checkPhoneNumber, checkEmailFormat");
}
function checkEmailFormat() {
// Ensure email contains '@'
return Find("@", this.email);
}
3. Conditional validation using `condition`
function config() {
// Only validate phone number if the country is US
validateOnUpdate("checkPhoneNumber", condition="this.country == 'US'");
}
4. Skip validation under certain conditions using `unless`
function config() {
// Skip phone number validation if the user is an admin
validateOnUpdate("checkPhoneNumber", unless="this.isAdmin");
}
Copied!