Event handler for multiple events

I’m not sure that everybody is aware that a single event handler method (in Dynamics 365 for Finance and Operations) can be decorated with several event handler attributes.

For example, a common method can handle both inserts and updates.

[
    DataEventHandler(tableStr(MyTable), DataEventType::Inserted),
    DataEventHandler(tableStr(MyTable), DataEventType::Updated)
]
public static void myHandler(Common _sender, DataEventArgs _e)

Or it can handle similar events from different sources, such as different tables:

[
    DataEventHandler(tableStr(InventItemSalesSetup), DataEventType::Inserting),
    DataEventHandler(tableStr(InventItemPurchSetup), DataEventType::Inserting),
    DataEventHandler(tableStr(InventItemInventSetup), DataEventType::Inserting)
]
public static void myHandler(Common sender, DataEventArgs e)
{
    InventItemOrderSetupMap inventSetup = sender;
    ...
}

If you want to run the same logic, simply using the same method makes good sense.

Leave a Reply

Your email address will not be published. Required fields are marked *