Standard Dynamics AX lookups
can be created in seconds without any programming knowledge. They are
based on table or extended data type relations. If the relation is set
on an extended data type, then all tables using this type will have
automatic lookups based on extended data type. For example, if we look
at the ItemId extended data type, we see that it is related to ItemId field in InventTable table. That means every control in the system bound to this extended data type will have automatic lookup to the InventTable table. It is also possible to override extended data type
relations by specifying relations on the table itself. In this case,
lookup will be based on the relations of the table. For example, we can
create some relation on the SalesLine table and extend it to have an additional related fixed field ItemType equal to 2. In this case, all controls bound to the ItemId field in the SalesLine table will have a lookup showing only items of type 2, i.e. service.
As an example, we will create a default customer method of payment in the Customer group form.
How to do it...
1. Open the CustGroup table in AOT, and add a new field:
Property
|
Value
|
---|
Type
|
String
|
Name
|
PaymMode
|
ExtendedDataType
|
CustPaymMode
|
2. Add the newly created field to the end of the Overview field group of the table.
3. To check the results, open Accounts receivable | Setup | Customer groups, and notice a new Method of payment column with the lookup:
How it works...
The newly created PaymMode field extends the CustPaymMode extended data type that has a defined relation to the CustPaymModeTable table. This relation ensures that our field and its form control have automatic lookup. By adding this field to the Overview field group, we make sure that it appears automatically in the Customer group form's grid in the Overview tab page.
There's more...
The automatically generated lookup, in the example above, has only two columns— Method of payment and Description.
Dynamics AX allows us to add more or change existing columns with
minimum effort by changing various properties. Lookup columns can be
controlled at several different places:
1.
Relation fields, either on an extended data type or a table itself, are
always shown on lookups as columns. In our example, the extended data
type CustPaymMode has a relation with PaymMode field in the CustPaymModeTable table and that's why it is displayed on the lookup.
2. Fields defined in table TitleField1 and TitleField2 properties are also displayed as lookup columns. We can see that Method of payment is specified in TitleField1 of the CustPaymModeTable table and Description is specified in TitleField2.
3. The first field of every table index is displayed as a column. If we look again in our example, we can see that the CustPaymModeTable table contains an index CustPaymModeIdx, which consists of the PaymMode field. This field is displayed as a lookup column.
4. The index fields, TitleField1 and TitleField2, are in effect only when the AutoLookup field group of the table is empty. Otherwise, the fields defined in the AutoLookup group are displayed as lookup columns.
Duplicate fields are shown only once. In our example, we can see that TitleField1 is set to PaymMode and TitleField2 is set to Name. The extended data type relation is based on the PaymMode field, which is the same as TitleField1. The only index, CustPaymModeIdx also contains the PaymMode field. That means our lookup will have only two columns— PaymMode (labeled as Method of payment) and Name (labeled as Description).
Now, to demonstrate how the AutoLookup group can affect lookup columns, let's modify the previous example by adding another field to this group. Let's add the PaymAccount field to the AutoLookup group on the CustPaymModeTable table. Now, the lookup has one more column:
In this way we can quickly add more fields into lookups.
It is also possible to add display methods to the lookup's column list. We can extend our example by adding the paymAccountName()
display method to the AutoLookup group on CustPaymModeTable. And here is the result: