I've 2 different lookup scenarios.. if the user chooses AccountNum field for VendTable, a lookup with all vendors show be shown for him to choose from..
and if he chooses VendGroup field he'll get a lookup with vendor groups.
The problem is:
When he choose AccountNum as field and use Vendors lookup and then add another record and choose VendGroup as a field.. the lookup will not show vendor groups but rather show all vendors instead and vice versa.
So, it depends on the field he uses the lookup for first, if he chooses VendGroup then it'll show vendor groups always even if the field is AccountNum!
In other words, it doesn't toggle lookup method more than once!
Here's my code:
This is a global variable among the class
SysLookupMultiSelectCtrl msctrl;
and this is the code in the datasource field methods:
[DataField]
class Value
{
public void lookup(FormControl _formControl, str _filterStr)
{
FormStringControl frmStringCtrl;
frmStringCtrl = element.design().controlName(formControlStr(SetupForm,Grid_Value));
if(SetupTable.Field == 'VendGroup')
{
Query q;
QueryBuildDatasource qbds;
q = new Query();
qbds = q.addDataSource(tableNum(VendGroup));
qbds.addSelectionField(fieldNum(VendGroup, VendGroup));
qbds.addSelectionField(fieldNum(VendGroup, Name));
msctrl = SysLookupMultiSelectCtrl::constructWithQuery(_formControl.formRun(),frmStringCtrl,q);
}
if(SetupTable.Field == 'AccountNum' && SetupTable.TableOption == TableOption::VendTable)
{
Query q;
QueryBuildDatasource qbds,qbds_DirPtyTable;
q = new Query();
qbds = q.addDataSource(tableNum(VendTable));
qbds.addSelectionField(fieldNum(VendTable, AccountNum));
qbds_DirPtyTable = qbds.addDataSource(tableNum(DirPartyTable));
qbds.addSelectionField(fieldNum(DirPartyTable, Name));
qbds_DirPtyTable.relations(true);
msctrl = SysLookupMultiSelectCtrl::constructWithQuery(_formControl.formRun(),frmStringCtrl,q);
}
}
public void modified()
{
SetupTable.Value = con2Str(msctrl.getSelectedFieldValues(),',');
super();
}
}