Model Object
addErrorToBase()
Signature
Section titled “Signature”addErrorToBase() — returns void
Available in: model
Category: Error Functions
Description
Section titled “Description”Adds an error on the object as a whole (not tied to any specific property).
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message | string | yes | — | The error message (such as “Please enter a correct name in the form field” for example). |
name | string | no | — | A name to identify the error by (useful when you need to distinguish one error from another one set on the same object and you don’t want to use the error message itself for that). |
Examples
Section titled “Examples”// 1. Add a general error on the object (not tied to any single property)
user = model("User").findByKey(params.userId);
user.addErrorToBase(message="Your account has been locked. Please contact support.");
// 2. Add a named base error so it can be targeted or cleared later
order = model("Order").findByKey(params.orderId);
order.addErrorToBase(message="This order cannot be placed outside business hours.", name="businessHoursViolation");
if (order.hasErrors(name="businessHoursViolation")) {
// handle the named error
}
// 3. Use addErrorToBase inside a custom validation method on the model
function validate() {
if (this.totalAmount > creditLimit()) {
this.addErrorToBase(message="The total amount exceeds your available credit limit.");
}
}