Changing a Relationship Precedence in Dynamics AX

By Brandon Carmichael | October 31, 2016

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?

relationship-precedence_brandon

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.

relationship-precedence_brandon-2

To change what relationship takes precedence I overloaded the init() method.

relationship-precendence_brandon-3

  1. 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();
}

Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!