- No conflicts during platform upgrades
- Better code separation for long-term maintenance
- Compliance with Microsoft's One Version policy
Event Type | Purpose |
---|---|
Pre-event | Executes before the standard method – ideal for validations |
Post-event | Executes after the method – great for additional processing |
OnModified, OnValidated | Used for form field-level triggers |
DataEventHandlers | Fire during insert/update/delete events on tables |
class VendTableEventHandler
{
[PostHandlerFor(tableStr(VendTable), tableMethodStr(VendTable, insert))]
public static void VendTable_PostInsert(XppPrePostArgs args)
{
VendTable vendTable = args.getThis() as VendTable;
if (!vendTable)
return;
vendTable.selectForUpdate(true);
vendTable.VendCode = VendTableEventHandler::generateVendorCode(vendTable.RecId);
vendTable.doUpdate();
}
private static str generateVendorCode(RecId recId)
{
return strFmt("VEND-%1", recId);
}
}
Tips to Keep in Mind
- Keep event logic focused - Don’t clutter handlers with business rules. Move complex logic into helper or service classes.
- Naming matters - Use consistent names like
VendTableEventHandler
so future developers can easily trace logic. - Avoid assumptions about execution order - If multiple handlers exist, the order isn’t guaranteed — so design your logic to be independent.
When to Use Event Handlers vs. Chain of Command
Both are powerful, but they serve different purposes:
Use case | What to use ? |
---|---|
Working with public table/form methods | Event Handler |
Modifying protected business logic (services, controllers) | Chain of Command |
Handling table-level inserts/updates | DataEventHandler |
UI interaction (field validations) | Form event methods |
That's all for now. Please let us know your questions or feedback in comments section !!!!