Creation of form based on inheritance tables without “Specifying type of new record” dialog box.
First of all we will need set of tables with inheritance applied. To do so follow the white paper provided my Microsoft:
When creating inheritance tables Microsoft Dynamics AX 2012 will add automatically relations to them but you might come across an error like this: “Duplicate relation name Organization detected in table inheritance.” This simply occurs as in both NoneProfitOrganization and GovernmentOrganization table Dynamics AX created relations with the same name in this case “Organization”. To resolve this issue simply rename one of the relations.
When all the tables with inheritance are set up we can move onto creating form.
In the white paper there is chapter about forms but it creates form where we need to use the dialog to select what type of record will be creating.
In this scenario we want Dynamics AX automatically detect where to create record depending what will be visible at the moment.
So let’s create from template SimpleList form and call it “Party”. Add the base “Party” table to data sources and save it.
You can see all the inheritance tables in the derived data sources:
Now we will want to be able to see fields from base table and fields tables rom each derived table.
So let’s add to the grid some of the fields from base table “Party” and from one of the derived e.g. “Person”. Now whenever we will want to add new record it will asks as what type should create:
Let’s create two record one type “Person” and other one type ”Government Organization” and see what has happened on the form some of the fields have been crossed out:
So every time we create different record we will only be able to access those fields that are assigned to it. So what if we want to only see fields assigned to specific type? Let’s change the form a little bit. We need to add our created enum to the top of the form and created grids for each table we will want to see. We will need to make the grid not visible and add some code so the form should look like this with properties:
New form method setControls():
Override init() method on form:
Override selectionChange() method on RelationType combo box:
Override clicked() method on both New and Delete buttons:
Now we can see only those fields which belongs to specific table according to selected type:
But still every time we create record we will still need to specify in which table plus derived data sources do not show inherited fields. To be able to see them we need to add the actual tables(so in our case “Person” and “GovernmentOrganization”) to forms data source and change property data source on grids to those tables(make sure all the fields specified previously are updated as well). So it should look like this:
No we can move swiftly between different tables and create record only in which is visible at the moment. We will not see as well the dialog for selecting the type as Microsoft Dynamics AX will be handling it now by picking what is set visible.
This provides us clean and easy functionality. The advantages are:
- We will not see any unnecessary fields (previously those were greyed out).
- Records visible are only those from selected type(previously we would see all records from based table).
- We can easily add more types by extending the inheritance.