AX – D365FO – Add methods to tables through extension – X++

You first create a new class in the extension model. This class will augment the InventTable table, and enable access to the table’s fields and methods in a manner that is easy to read and understand. It’s important that you choose the correct name for your augmentation class. This name must be unique across all types in all models that are deployed.

final class InventTableMy_Extension
    public void myDefaultInventLocationId()
        // This would have partner specific logic to initialize the new field.
        this.MyInventLocationId = this.inventLocationId();

You can now add new methods to the augmentation class. These methods will then appear in IntelliSense for variables of the InventTable type, just as if they were defined directly on the table. This behavior applies to both static methods and instance methods.

There are a few rules for augmentation classes:

  • They must be final.
  • They must be suffixed by _Extension.
  • They must be decorated with the [ExtensionOf()] attribute.

Now you can use your new method, for example, from an event handler:

class InventTableMy_EventHandler
    [DataEventHandler(tableStr(InventTable), DataEventType::Inserting)]
    public static void InventTable_onInserting(Common sender, DataEventArgs e)
        InventTable inventTable = sender as InventTable;
        // Call the method as if it was defined directly on InventTable.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s