web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Multi-Table Lookups (SysMultiTableLookup)

adam260 Profile Picture adam260 1,871
When creating an override lookup method that needs to return data from multiple tables you will need to be sure to use the SysMultiTableLookup class instead of SysTableLookup class. If you do not then whenever you run the fieldnum() function it will try to use the field id on the initial table instead of the one you are referring to. Below is an example on how to run a lookup to get the UOM symbols and descriptions for a special unit class uom.

 Query                   query;
    QueryBuildDataSource    queryBuildDataSourceTable;
    QueryBuildDataSource    queryBuildDataSourceTableDescriptions;
    QueryBuildRange         queryBuildRange;
    //you need to define the multitable, but initalize it AFTER you have defined the query
    //SysTableLookup          sysTableLookup  = SysTableLookup::newParameters(tableNum(UnitOfMeasure), ctrl);
    SysMultiTableLookup sysTableLookup;
    query = new Query();

    queryBuildDataSourceTable = query.addDataSource(tableNum(UnitOfMeasure));
    //join the translation table so we can get a description of the UOM
    queryBuildDataSourceTableDescriptions = queryBuildDataSourceTable.addDataSource(tableNum(UnitOfMeasureTranslation));
    queryBuildDataSourceTableDescriptions.joinMode(JoinMode::InnerJoin);
    queryBuildDataSourceTableDescriptions.relations(false);
    queryBuildDataSourceTableDescriptions.addLink(fieldNum(UnitOfMeasure,RecId),fieldNum(UnitOfMeasureTranslation,UnitOfMeasure));

    //filter by the unit class being passed
    queryBuildRange = queryBuildDataSourceTable.addRange(fieldNum(UnitOfMeasure, UnitOfMeasureClass));
    queryBuildRange.value(queryValue(unitClass));
    //define multiple table lookup query
    sysTableLookup  = SysMultiTableLookup::newParameters(ctrl, query);
    //add which fields will be displayed to the user (symbol + desc.)
    sysTableLookup.addLookupfield(fieldNum(UnitOfMeasure, Symbol), true);
    sysTableLookup.addLookupfield(fieldNum(UnitOfMeasureTranslation, Description), 2);
    //do not use for multi table
    //sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

This was originally posted here.

Comments

*This post is locked for comments