Interview Questions

Thursday, December 21, 2017

How to create lookup method in ax 2012....

Hi Guys,

Scenario:
1- If you want to show any lookup on form's field
2- If master table field lookup you want to show in parent table 2 fields.
For ex-
You have Parent table "DiscountMaster" and field "MasterID"
and Child table "Discount Details" and fields "Discount Master ID", "Discount Code"

Now, if you want to show the lookup in fields "Discount Master ID", "Discount Code"
then normal solution is "you need to create relation with parent table" but whenever you will go to create normal relation between 2 fields of child table with 1 field of parent table then in the second record of relation will not show the complete lookup value. It will show only first field selected value in lookup. Then in this case you need to override lookup method:

For that please use below code;

public void lookup()
{
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildRange queryBuildRange;

    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(DiscountMaster), this);

    sysTableLookup.addLookupField(fieldNum(DiscountMaster, MasterID));

    queryBuildDataSource = query.addDataSource(tableNum(DiscountMaster));
 

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

    //super();
}

it will solve your issue.

Note: Don't forget to remove relation with second field.