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.
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.
It is actually very easy to combine multiple datasources in a sysTableLookup. Here is the trick I used to be able to filter on the name from the EcoResProductTranslation
in the lookup for items.
1) Create a view that combines all your datasources and add the fields you would like to see in your lookup to the view.
2) Create a query from the view created in step 1.
3) Use these to perform your lookup as follows...
static client void lookupItemActive(FormStringControl _ctrl)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(<ViewName>),_ctrl);
Query query = new Query(queryStr(<QueryName>));
sysTableLookup.addLookupfield(fieldnum(<ViewName>, ItemId));
sysTableLookup.addLookupfield(fieldNum(<ViewName>, Name));
sysTableLookup.addLookupfield(fieldNum(<ViewName>, ItemGroupId));
sysTableLookup.addLookupfield(fieldnum(<ViewName>, Status));
sysTableLookup.addLookupfield(fieldnum(<ViewName>, RevId));
sysTableLookup.addLookupfield(fieldnum(<ViewName>, ItemType));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
来源:https://stackoverflow.com/questions/14659999/how-to-create-a-lookup-with-fields-from-more-than-one-datasource