Jun 14, 2012

Creating a form for lookup

The following code is to performing form lookup for a field on another form..

Step 1 : Create a form (EmplIdLookupForm) with the required fields(Lookup form)
 
  - Override the form level init() and run() as

void init()
{
    ;

    super();

    element.selectMode(emplTable_EmplId);
}

public void run()
{
    FormStringControl callingControl = SysTableLookup::getCallerStringControl(element.args());
    boolean filterLookup;
    ;

    filterLookup = SysTableLookup::filterLookupPreRun(callingControl, emplTable_EmplId, emplTable_ds);

    super();

    SysTableLookup::filterLookupPostRun(filterLookup, callingControl.text(), emplTable_EmplId, emplTable_ds);
}

- Override the forms DataSource Level init() as

void init()
{
    Query   query = new Query();
    ;
    super();

    query.addDataSource(tablenum(EmplTable));

    this.query(query);
}

Step 2 : Override the Lookup caller form field's Lookup() with following code

FormRun formRun;
    Args args;
    ;

    args = new Args(formstr(EmplIdLookupForm));
    args.caller(this);
    formRun = ClassFactory::formRunClassOnClient(args);
    formRun.init();
    this.performFormLookup(formRun);

No comments: