Creating a run-time lookup form

A standard lookup form is created through relations on the database table, and on the Extended Data Type. To learn about the standard lookup form, click .

If, however, you need to create a runtime lookup form that looks up other database fields than the ones offered by the standard lookup form, use the application class SysTableLookup and override the lookup method on the relevant form control.

How to use the SysTableLookup class

 

  1. Create a new instance of SysTableLookup where 'this' is the current form control

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

  1. Add the fields to be shown in the lookup form

    sysTableLookup.addLookupField(fieldNum(custTable, accountNum));

  1. Limit the data selection.

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

    queryBuildRange      = queryBuildDataSource.addRange(fieldNum(custTable, accountNum));

    queryBuildRange.value('A..B');

    sysTableLookup.parmQuery(query);

  1. Perform the lookup, and delete super().
    super() will create an autogenerated lookup form.

    sysTableLookup.performFormLookup();

//    super()

}

 

A complete example of overriding the lookup method on a form control

 

void lookup()

{

    Query                   query          = new Query();

    QueryBuildDataSource    queryBuildDataSource;

    QueryBuildRange         queryBuildRange;

 

// Create an instance of SysTableLookup where 'this' the current Form control.

 

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

    ;

 

// The field to be shown in the lookup form.

 

    sysTableLookup.addLookupField(fieldNum(custTable, accountNum));

    sysTableLookup.addLookupField(fieldNum(custTable, name));

 

// Limit and arrange data selection.

 

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

    queryBuildRange      = queryBuildDataSource.addRange(fieldNum(custTable, accountNum));

    queryBuildRange.value('A..B');

    sysTableLookup.parmQuery(query);

 

// Perform lookup

 

    sysTableLookup.performFormLookup();

 

// do not call super().

 

//    super()

}

 

 

 

 

 

void lookup()

{

  Query query = new Query();

  QueryBuildDataSource queryBuildDataSource;

  QueryBuildRange queryBuildRange;

  SysTableLookup sysTableLookup;

  TableId tableId;

  FieldId fieldId;

  ;

  tableId = tablename2id('myTable');

  sysTableLookup.parmTableId(tableId);

  fieldId = fieldname2id(tableId, 'MyField_1');

  sysTableLookup.addLookupfield(fieldId);

  fieldId = fieldname2id(tableId, 'MyField_2');

  sysTableLookup.addLookupfield(fieldId);

 

  queryBuildDataSource = query.addDataSource(tableId);

  queryBuildDataSource.orderMode(OrderMode::GROUPBY);

  queryBuildDataSource.addSortField(fieldId));

 

  sysTableLookup.parmQuery(query);

 

  this.performFormLookup(sysTableLookup.formRun());

}

This manner of creating a lookup form is used in the DocuType form in the application. The full path to the modified lookup method is:

\Forms\DocuType\Designs\Design\[Tab:Tab]\[TabPage:Overview]\[Grid:Grid]\StringEdit:ActionClassName\Methods.

Note

The SysTableLookup is limited to making lookups on fields in a table.