Types of Graph Event Handlers

MYOB Acumatica Framework provides two types of graph event handlers: classic and generic. To declare a classic event handler, you specify the DAC name, the field name, and the type of event in the handler name. To declare a generic event handler, you specify the field name and the DAC name as type parameters of the event type. Both types of event handlers work the same.

We recommend using generic event handlers because they are easier to declare, use, and validate in Visual Studio. To refactor classic event handlers into generic event handlers, you can use Acuminator.

Note:
All examples in the subsequent topics demonstrate generic event handlers.

Classic Event Handlers

Classic event handlers have the following signature:

  • For row-level events:
    protected virtual void [DACName]_[RowEventName](…)
  • For field-level events:
    public virtual void [DACName]_[FieldName]_[FieldEventName](…)

For example, a classic handler for the RowSelected event of the CROpportunityProducts DAC is defined as follows.

protected virtual void CROpportunityProducts_RowSelected(
    PXCache sender, PXRowSelectedEventArgs e) {
…}

Generic Event Handlers

Generic event handlers have the following signature:

  • For the row-level events:
    public virtual _(Events.[RowEventName]<[DACName]> e)

    For example, a generic handler for the RowSelected event of the CROpportunityProducts DAC is defined as follows.

    protected virtual void _(Events.RowSelected<CROpportunityProducts> e)
  • For the field-level events:
    public virtual _(Events.[FieldEventName]<[DACName], [FieldName]> e)

    For example, a generic handler for the FieldUpdated event of the CROpportunityProducts.contactID field is defined as follows.

    protected virtual void _(Events.FieldUpdated<CROpportunityProducts.contactID> e)
    Specifying the DAC name as a parameter is optional because the system determines it automatically based on the field name. You should specify the DAC name explicitly if the field is inherited and you want to declare an event handler for the inherited field. For example, the FieldDefaulting event handler for the CurrencyInfo.moduleCode field looks as follows.
    protected override void _(Events.FieldDefaulting<CurrencyInfo, 
      CurrencyInfo.moduleCode> e)

You can declare more than one handler for the same event by adding a custom name (for example, a number) after the event name as follows.

public virtual _(Events.[EventName]2<[DACName], [FieldName]> e)

The following example shows the second event handler for the FieldUpdated event of the CROpportunityProducts.contactID field.

protected virtual void _(Events.FieldUpdated2<CROpportunityProducts.contactID> e)

However, we do not recommend declaring more that one event handler because .NET framework does not determine the call order.