How to create a lookup with fields from more than one datasource?

Mohd Saddaf khan picture Mohd Saddaf khan · Feb 2, 2013 · Viewed 15.2k times · Source

I need to create Dynamic lookup in my form field which should display fields from two different datasources.. I am trying to perform it as:

  public void lookup()
  {

    query = new Query();
   sysTableLookup = SysTableLookup::newParameters(tableNum(smmBusRelTable), this);
  qbds = query.addDataSource(tablenum(smmBusRelTable));
 // qbds.addDataSource(tableNum(DirPartyTable));
 //qbds.relations(true);

sysTableLookup.parmQuery(query);   
sysTableLookup.addLookupField(fieldNum(smmBusRelTable, Busrelaccount));
//sysTableLookup.addLookupfield(fieldNum(DirPartyTable, Name));


 sysTableLookup.performFormLookup();
}

Commented lines are the operation I am trying to perform to add different datasource.

Answer

Björn Olievier picture Björn Olievier · Feb 2, 2013

As far as I know the SysTableLookup class does not support showing fields from other tables. The addLookup() method doesn't take a TableId and assumes all fields are in the first datasource of the query.

You could write your own version of SysTableLookup that supports referencing fields from various tables. A simpler and more practical (and less expensive) approach might be to create a display method on SmmBusRelTable to fetch the name from DirPartyTable (if it doesn't already exists) and use that as a field in the lookup. Display methods on the main table are supported if I remember correctly.

Depending on what exactly you're trying to accomplish there might be an even simpler way. You could add the display method to the AutoLookup table field group of SmmBusRelTable and avoid having to override the lookup() method.