Table Extension Event Example in D365 F&O with Example

Rumman Ansari   Software Engineer   2023-10-27   1855 Share
☰ Table of Contents

Table of Content:


Table Event Handler in d365

In Microsoft Dynamics 365, a table event handler is a type of event handler that is used to handle events that are raised for tables in the application database. Table event handlers are used to add or modify the functionality of the standard application, without modifying the original code of the application.

Here is an example of how to create a table event handler in D365:

  1. Open the AOT (Application Object Tree) in Dynamics 365.
  2. Expand the Data Model node, and then select Tables and right click then open design.
  3. Expand the table see Event the Right-click on the table for which you want to create an event handler and select "Copy Event Handler Method".
  4. In the Event Handler dialog box, select the event you want to handle (for example, OnInsert).
  5. In the Class Name field, enter a name for the new class that will handle the event.
  6. Click the Add button to create the new class.
  7. In the class editor window, write the code that will handle the event.

Here is an example of code for a table event handler that handles the OnInsert event:


class MyTableEventHandler
{
    [DataEventHandler(tableStr(MyTable), DataEventType::OnInsert)]
    public static void MyTable_OnInsert(Common sender, DataEventArgs e)
    {
        MyTable myTable = sender as MyTable;
        if (myTable)
        {
            // Do something when a new record is inserted in MyTable
        }
    }
}

In this example, the MyTable_OnInsert method is called when a new record is inserted in the MyTable table. The method receives two parameters: the sender object (which is the table that raised the event) and the event arguments (which contain information about the event).

Table event handlers are a powerful tool for customizing the functionality of Dynamics 365 without modifying the original code of the application. They allow you to add new features, customize the behavior of existing features, or integrate with external systems.

Screenshot

You can see a table structure and events present inside it.

Table Event Handler in d365

Note: Events are exposed on the designer on different element and sub-element types, like table events, form events, form data source events, form control events, and others. Open the context menu of an event node to interact with events:

Table Event Handler in d365
  • Copy event handler method: This option copies a method signature to the clipboard. You can paste it in any X++ code editor to define a method that subscribes to the selected event.