问题
I have a table of items that each reference one other item in another table. We'll say the items are people, and the related items are favorite foods.
Table A: Bob:1, Sally:1, Sue:3
Table B: 1:Apples, 2:Bananas, 3:Oranges
The "people" are tied to their favorite "foods" by the food RecId, refererenced in the People table.
I have a form/grid for editing people. Is there a way to cause the FoodRecId StringView in the grid to convert its value so the RecId numbers are not visible in the grid?
I've already written multi-column lookups to easily handle creating correct relations, but if the RecIds in the grid could be hidden/replaced, the form will be much easier to use.
回答1:
Way easy if you are using AX 2012: use surrogate keys.
Use of RecId
as foreign keys are now Best Pratice!
Update: The exact steps can be found in AX Musings.
If using an older version of AX then have a look on the use of ContactPersonRecId
in the CustTable
form.
It involves hiding the recId
field in the form while using another edit field ContactPersonName
as the key.
While the use of RecId
as a foreign key is not against Best Practice it is usually avoided due to the complexity of manually handling surrogate keys.
回答2:
Brad,
ReplacementKey is the solution for you.
It is possible now in AX 2012 to define parent/child relationship without having to define the same primary key in both the tables. For eg, till AX 2009, a header/lines relationship used to exist on the basis of a unique key like SalesId field in both SalesTable and SalesLine. This is no more required in AX 2012. Such relations are defined on RecIds and values are displayed on forms depending on what is defined on your ReplacementKey (thats why the name Replacement!) Instead of RecId, you can show any other filed like name.
Check out my blog! http://amannain.blogspot.in/2012/04/table-relationships-learning-with.html
来源:https://stackoverflow.com/questions/10281031/how-to-use-recid-as-a-foreign-key-in-a-form