Changing a Relationship Precedence in Dynamics AX
Have you ever been in a scenario where a data source has more than one relationship to a table it is being linked to? I have. It wasn’t a problem until I wanted the second relationship to take priority.
So the real question is, how to specify what relationship should the table use?
In my example, on the InventTable I have multiple relationships defined. Please note though:
InventTable.AlcholoManufacturerID_RU == VendTable.AccountNum InventTable.PrimaryVendorId == VendTable.AccountNum
On my form: EcoResProductDetailsExtended, I added VendTable as a data source.
Well, how does AX know which relationship I want take precedence? By default, AX uses the first one. In this case, the AlcoholManufacturer_RU relationship takes precedence.
To change what relationship takes precedence I overloaded the init() method.
- First, you must tell the data source what relationship you want to use.
vendtable_ds.joinRelation("PrimaryVendTable");
2. Second, you must make the relationship the active relationship.
VendTable_ds.linkActive();
3. Third, you must execute the query.
vendtable_ds.executeQuery();
It is important to note, this must all be done before the super(). By following these simple steps, you will set a tables relationship precedence on a data source with more than one defined relationship.
Your init() method should look like the following.
public void init() { vendtable_ds.joinRelation("PrimaryVendTable"); VendTable_ds.linkActive(); vendtable_ds.executeQuery(); super(); }