Skip to content

Model Object

addErrorToBase()

addErrorToBase() — returns void

Available in: model Category: Error Functions

Adds an error on the object as a whole (not tied to any specific property).

NameTypeRequiredDefaultDescription
messagestringyes—The error message (such as “Please enter a correct name in the form field” for example).
namestringno—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).
// 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.");
    }
}