Table relation selection is faulty and not extension-friendly
Views (229)
Hello AX World,
Table relations help ease the creation of the link between two data sources.
E.g. if you have SalesTable and SalesLine and want to link them together in a form, you only need to do the following:
Moreover, it could go even worse, consider the scenario when you have multiple extensions having relations to the same related table for different purposes.
You cannot determine which relation will be taken; it will be "random".
I was adding a couple of fields to the BOM table.
One field was an enum TableGroup and the other one was named Relation which contain values based on TableGroup field.
If the value Table is selected in TableGroup field, then the Relation field would show Items, if the value Group is selected, then it would show BOMs.
To get the lookup right, I created a couple of relations. One to the InventTable and another one to BOMTable.
Table relations help ease the creation of the link between two data sources.
E.g. if you have SalesTable and SalesLine and want to link them together in a form, you only need to do the following:
- Make sure the relation to the parent table (SalesTable) exists on the child table (SalesLine).
- Set SalesTable as a related table on SalesLine data source in a form.
Once you have it, the data sources will be linked dynamically.
Sounds simple.
The problem
What if we have multiple relations between the same tables for the different purposes?
SalesLine has two relations to SalesTable in the standard code. How does the system know which relation to pick?
SalesLine has two relations to SalesTable in the standard code. How does the system know which relation to pick?
I noticed that it selects the topmost relation to the related table. So, if you have two, it will select the first one in the relations list. In this case, relation #1 in the screenshot as it is above #2.
What if suddenly #2 moves to the top?
In fact, all forms having dynamic links between those two tables would start using relation #2 by default and will break their intended purpose.
In fact, all forms having dynamic links between those two tables would start using relation #2 by default and will break their intended purpose.
It would be a breaking change.
While this problem is manageable in the same model context, it a big problem in extensions.
Relations in extensions are put on top of the list and there is no way of moving them down. It only goes down as far as the last relation in the extension.
Side note: this extension of SalesTable in Revenue Recognition model broke my extension code once when it was released.
Moreover, it could go even worse, consider the scenario when you have multiple extensions having relations to the same related table for different purposes.
You cannot determine which relation will be taken; it will be "random".
One more example
Let me show you one recent example that I had with BOM and BOMTable.
One field was an enum TableGroup and the other one was named Relation which contain values based on TableGroup field.
If the value Table is selected in TableGroup field, then the Relation field would show Items, if the value Group is selected, then it would show BOMs.
To get the lookup right, I created a couple of relations. One to the InventTable and another one to BOMTable.
Notice that BOM have already had relation to BOMTable. In the extension, I created another relation to the BOMTable, which overruled the other relation as it was topmost now. And I could not bring it down below the standard relation.
This broke the BOMTable form and all other forms that relied on this relation. Now tables BOMTable and BOM are dynamically linked using new relation which is incorrect and results in wrong outcome shown on the form.
I have made an intrusive customization unintentionally.
Yes, it can. Relations on queries pick relations the same way. The lookup and form references (form refs) work similarly.
The standard lookup to the field will be taken on the first relation from the top that involves that field.
The form reference on a field will be taken from the first relation that links this field to some table. And if you have two relations linked using the same field, the table from the topmost relation will be taken for the form reference.
I blogged about this issue in the past (link).
Can it be worse?
Yes, it can. Relations on queries pick relations the same way. The lookup and form references (form refs) work similarly.
The standard lookup to the field will be taken on the first relation from the top that involves that field.
The form reference on a field will be taken from the first relation that links this field to some table. And if you have two relations linked using the same field, the table from the topmost relation will be taken for the form reference.
I blogged about this issue in the past (link).
My wish
I strongly believe that relation selection based on it's position in the list should be replaced by something more intelligent.
Current behavior is not extension friendly and it welcomes unintentional intrusive customizations and risks introducing a breaking change.
As a developer I should be able to define relations in a non intrusive way. I should not be writing code to fix faulty behavior.
And if I would like to overrule the standard behavior, I should be able to do it declaratively.
Current behavior is not extension friendly and it welcomes unintentional intrusive customizations and risks introducing a breaking change.
As a developer I should be able to define relations in a non intrusive way. I should not be writing code to fix faulty behavior.
And if I would like to overrule the standard behavior, I should be able to do it declaratively.
What do you think? Should this be changed?
Am I missing something?
Let me know!
Be aware and take care!
This was originally posted here.

Like
Report




*This post is locked for comments