View Event Handlers
Views support the same DataEventHandler pattern as tables, since both inherit from Common. Event handlers allow you to subscribe to lifecycle events on a view without modifying its source code.
Since views are typically used for read operations, the most commonly used events are related to validation and post-load processing. However, the full set of data events is available if the view supports write operations.
Registering an Event Handler
class SAMOCustTransViewEventHandlers
{
[DataEventHandler(tableStr(SAMOCustTransView), DataEventType::PostLoad)]
public static void SAMOCustTransView_onPostLoad(Common _sender, DataEventArgs _e)
{
SAMOCustTransView view = _sender as SAMOCustTransView;
// Post-load enrichment
}
}
Common View Events
| Event | Use Case |
|---|---|
PostLoad | Populate computed/display fields after the record is loaded from the view. |
ValidatedWrite | Add validation when the view supports insert/update (e.g., updatable views). |
ValidatedField | Field-level validation for form-bound view fields. |
InitializedRecord | Set default values when a new record is created through the view. |
Example: Validating a View Record
class SAMOCustTransViewEventHandlers
{
[DataEventHandler(tableStr(SAMOCustTransView), DataEventType::ValidatedWrite)]
public static void SAMOCustTransView_onValidatedWrite(Common _sender, DataEventArgs _e)
{
ValidateEventArgs validateArgs = _e as ValidateEventArgs;
SAMOCustTransView view = _sender as SAMOCustTransView;
if (validateArgs.parmValidateResult()
&& view.AmountMST == 0)
{
validateArgs.parmValidateResult(
checkFailed("@SAMO:AmountCannotBeZero"));
}
}
}
Refer to the Table Event Handlers page for the complete DataEventType reference — the same events and delegate signatures apply to views.