General X++ Development

How do I create an event handler in D365FO?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I create an event handler in D365FO?

SSunny Vasty90 reputation · answered Aug 13, 2026

Create a handler method and decorate it with the event attribute.

Example for a table insert event:

X++
final class MyEventHandlers
{
    [DataEventHandler(tableStr(CustTable), DataEventType::Inserted)]
    public static void CustTable_onInserted(Common _sender, DataEventArgs _e)
    {
        CustTable custTable = _sender as CustTable;

        if (custTable)
        {
            // Your logic.
        }
    }
}

Use the most specific event or extension point that matches what you need. Do not subscribe to a broad event and then add a pile of unrelated checks if there is a cleaner extension point.