Warm tip: This article is reproduced from stackoverflow.com, please click
lookup axapta x++ dynamics-ax-2012

How to Chose Name (or other Field) instead of ID in Lookup ax2012

发布于 2020-03-27 10:22:29

I am making a lookup by adding relation of one table to the other. I made my custom table and make a relation with HCMWorker. Now I added a relation in my custom table with HCMWorker.personalName. Than I make a form add a grid to it and drag that field to my grid. Now I have a lookup showing ID and Name. Now when I select any Item from the lookup table ID comesup into the field I want that Name will show up instead of ID. Any Solution ?

LookUp Selected Field

Questioner
Sohaib Anwaar
Viewed
30
rjv 2019-08-01 20:35

USUALLY the way to go about it would look like this:

Use the RecId of the HcmWorker table (parent) as the foreign key in your custom (child) table to take advantage of the Reference Group feature. This will allow you to create a field group that displays a different field than the actual RecId, but the underlying data in your custom table will still be a RecId of the HCMWorker table. Using the surrogate key/RecIds (instead of the natural key) as foreign keys is a Dynamics AX best practice.

  1. Add a RefRecid column in your custom table
  2. Add a foreign key relation in your custom table's RefRecId back to the parent table's RecId
  3. Add a field group to the parent table with just the name of the worker to use in the Replacement Field Group property on the Reference Group countrol.
  4. When you drag and drop the RecId field from the form datasource onto the form to create a new control you will be able to select the replacement field group.

HOWEVER This situation does not work with HcmWorker because the table does not contain the name due to database normalization. So while the above steps would be your generic solution, for your case there is a more advanced maneuver which involves creating a lookup form. Fortunately you do not have to create your own lookup form in this scenario; this has already been done for you.

Use (drag and drop) the HcmWorkerRecId EDT to your custom table, create a foreign key relation back to the HcmWorker table and the lookup form should automatically be put to use when you drag the field from the datasource list to create a new form control (see the Form Help property of the EDT). This lookup form will have the same look and feel as the rest of the application when selecting workers which is also a design best practice. Using this technique should default to displaying the name instead of ID.