Skip to main content

Dynamics 365 for operations – Table extensions

Background

Extensions are a new way to add functionality and custom code to the D365 system without changing the standard code. In fact, Microsoft has announced that edit standard elements like those that we have done in the past will not be possible after 2017.
By using extensions, we can achieve the same result by simply extending the standard system => EXTENSIONS.
To read more about the difference between overlaying and extensions follow this link https://ax.help.dynamics.com/en/wiki/customization-overlayering-and-extensions/#extensions

Extending tables

By using table extensions, we can create a new table that adds new fields, field groups, indexes, mappings, relations, methods, subscribe to event handlers and more.
When extending tables we need to follow the naming rule as such: <TABLENAME><_Extension> the compiler understands the _Extensions suffix and knows that the table in question is extending a table from the standard system. This gives us access to public methods of the standard table, the fields, indexes and so on.
Example
Let us say we need to extend the BOM standard table to add some more fields, new methods and subscribe to an event.
First we create a new table as we normally do and to adhere to the naming rule the extended table gets the name BOM_Extension. In our solution explorer, we get a new folder named Table Extensions and there we can see our new table.

Create new table extension


Adding new fields

Here four fields have been added to the BOM_Extension table and then we see the fields from the standard BOM table




Adding new methods and subscribing to events

In order to create new methods for the extended table we need to use a table extension class and the class needs to have the same name as the extended table, in our example the class should be named BOM_Extension. The class should be declared static
All methods must be declared public static and the first parameter MUST be the table that the class is extending. This parameter is though never passed on when calling the method, only the parameters that we add after the table buffer.

See the following screen shot of a simple method in a table extension class

Event handler

When subscribing to events/event handlers you can right-click the event under the Events note on the extended table and select “Copy event handler method”



Then just paste the code into the extension class and add some code that is needed in the event handler. In the following example, the onValidateField event handler is being handled. The Common parameter is the table buffer and the DataEventArgs is the event we are subscribing to. Then in this code example we instantiate the ValidateFieldEventArgs and give it the value of the “e” parameter.




Comments

Popular posts from this blog

Using the Dynamics Ax Office Add-in

Hi everyone, I have been playing around with some Ax 2012 stuff and I was testing the Office Add-in and I think it is preatty cool. In order to use the Office Add-in it has to be installed with the Ax client and some settings needs to be made in the system as well. Lets dive into how it can be done, this is how I tested this function and it can most certainly be done in different ways. First I created a small query called MyCustTableQuery Next step is to provide information about the query and expose it so we can use the query in our office application, my application of choice was Excel. In Dynamics Ax 2012 go to Organization Administration> Setup> Document Management > Document datasources Here it is possible to select a query or service, in my example I used the query. So here i added a new record of data source type Query and then I selected my newly created MyCustTableQuery . Now the query is ready to use in what ever office application we ha...