Search This Blog

May 24, 2013

Custom lookup for Dialog fields in Axapta [AX2012]

Custom lookup for Dialog fields in Axapta





Overriding the event methods (e.g. custom lookup, modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls, but the good news is that it is possible!
In order to override the event methods on dialog controls, the following needs to be done.
class TestDialogFields
{
    Dialog                   dialog;  
    DialogField           newProdIdField;
}
public static void main(Args args)
{
    TestDialogFieldstestDialogFields = new TestDialogFields();
     DialogRunbase               dialogRunbase;
    ;
    dialogRunbase = DialogControlOverload.showDialog();
    if(dialogRunbase.run())
    {
        // code for update  once the use selects a record from the lookup and click 'ok'
     }
}
Dialog showDialog()
{
    FormRun     formRun;
    ;
    dialog = new Dialog('Dialog fields test');
    newProdIdField = dialog.addField(typeId(ProdId));
    dialog.run(true);
    dialog.formRun().controlMethodOverload(true);
    dialog.formRun().controlMethodOverloadObject(this);
    return dialog;
}
If we want to create a Custom lookup
public void Fld1_1_lookup()
{
    FormStringControl control = dialog.formRun().controlCallingMethod();
    boolean ret;
    SysTableLookup          sysTableLookup =  SysTableLookup::newParameters(tablenum(Prodtable, control);
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    ProdTable               prodTable;
     ;
   prodTable = ProdTable::find(prodId);
sysTableLookup.addLookupfield(fieldnum(ProdTable, ProdId));
    sysTableLookup.addLookupfield(fieldnum(ProdTable, Name));
  //You can add the ranges for filtering
   sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
We can add all the other methods  as follows
public void Fld1_1_modified()
{
  // modify code goes here
}
public void Fld1_1_validate()
{
// validation code goes here
}
 
-Harry

1 comment:

  1. hi can you please tell me how you are passing the prodid and from where you fetched it.
    i am referring to the line
    prodTable = ProdTable::find(prodId);

    ReplyDelete

Thanks