Sunday, August 25, 2013

Customizing lookup in Dialog Field through code


Hello  Friends,

The following post shows you how to add a lookup to a dialog field through code. The lookup comes 
automatically when you use an EDT, but if you want to customize the lookup or you want lookup through the code then use below code. 

Step 1.  Create a class which extends Runbase and declare your 
dialog field here. For Example I will take Cust account for simplicity.

class Classname extends RunBase
{
     Dialog  dialog;
    DialogField     fieldAccount;
    CustAccount   custAccount; 
}

Step 2: override the dialog() method.

protected object dialog()
{
       dialog = super();
       fieldAccount = dialog.addField(extendedTypeStr(CustVendAc));
fieldAccount.lookupButton(2);
return dialog;
}
Step 3: override the getFromDialog() method.
protected boolean getFromDialog()
{
       custAccount  =  fieldAccount.value();
       return true;
}

Step 4:  override the dialogPostRun() method.
public void dialogPostRun(DialogRunBase _dialog)
{
       super(_dialog);
       _dialog.formRun().controlMethodOverload(true);
       _dialog.formRun().controlMethodOverloadObject(this);
}

Step 5: Now get the name of the control for which lookup is required. Use the below code.

fieldAccount.name();

Step 6:  Now write your lookup method by using the name of the control.
private void Fld1_1_lookup()
{
       SysTableLookup   sysTableLookup;
       FormControl formControl;
       Query q = new Query();
       QueryBuildDatasource     qbds;
       formControl  =  fieldAccount.control();
       if (formControl)
      {
            sysTableLookup =                SysTableLookup::newParameters(tablenum(CustTable), formControl);
           qbds = q.addDataSource(tableNum(CustTable));
sysTableLookup.parmQuery(q);
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.PerformFormLookup();
}

Now you are good to go. best of Luck.



























No comments:

Post a Comment