KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Validation Order in ORDA Entity Events
PRODUCT: 4D | VERSION: 21 | PLATFORM: Mac & Win
Published On: November 19, 2025
ORDA entity events allow validation at attribute and entity levels, with attribute-level firing first. However, the documentation lacks examples on chaining them to handle field-specific rules before entity-wide checks, avoiding redundant code or overlooked errors.
Below is an example in the ProductsEntity class that validates "price" individually (must be positive) before an entity-level check (net price after discount >= 10):


//ProductEntity
Class extends Entity

Function event validateSave price($event : Object) : Object
  If (This.price<=0)
    $result:={errCode: 1; message: "Price must be positive"; seriousError: False}
    return $result
  End if

Function event validateSave($event : Object) : Object
  $netPrice:=This.price*(1-This.productToDiscount.value)
  If ($netPrice<10)
    $result:={errCode: 2; message: "Net price too low"; seriousError: True}
    return $result
  End if



Example

var $d1:=ds.Discount.new()
$d1.ID:=1
$d1.value:=0.1
$d1.save()

var $p1:=ds.Product.new()
$p1.ID:=1
$p1.price:=5
$p1.discountID:=$p1.ID
$p1.save()

var $p2:=ds.Product.new()
$p2.ID:=2
$p2.price:=50
$p2.discountID:=$d1.ID
$p2.save()

$d1:=ds.Discount.get(1)
$d1.value:=0.25
$d1.save()


The entity $p1 cannot be saved with the current price and discount values; the net price is too low.