Tuesday, April 9, 2013

Data filteration in dialog box In Microsoft Dynamics AX 2012:

Let say for example, dialog box contains 2 dialog fields i.e. Customer group and Customer account.
Every customer is tagged to one customer group, so now when you enter the customer group in the dialog field of the customer group, the related customer accounts which are tagged to that customer group needs to be shown in the customer account dialog field.

Now to go the setup of the dialog box as shown in the screen shot

Override the control of the customer account dialog field with below code with the control name of the customer account dialog as “Fld2_1” as shown in the above screens hot.
public void Fld2_1_Lookup()
{
    SysTableLookup          sysTableLookup;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    Query                   query;
    FormStringControl       _control;
    ;

    sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable),dialogCustAccount.control());

    sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum));
    sysTableLookup.addLookupfield(fieldnum(CustTable, CustGroup));

    query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, custGroup));
    queryBuildRange.value(dialogCustGroupId.value());

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();
}

Now override the “dialogPostRun()” method from the override methods and the code after super() call as shown below.
public void dialogPostRun(DialogRunbase dialog)
{
    super(dialog);
    dialog.formRun().controlMethodOverload(true);
    dialog.formRun().controlMethodOverloadObject(this);
}

Result:


Below is the link for the entire code:
https://skydrive.live.com/?cid=0b5669924378bbb7#cid=0B5669924378BBB7&id=B5669924378BBB7%21232