Create a custom lookup with multiple data sources on form using X++
Open the form on which you want to create a custom lookup. Go the data source - fields, select field and override the lookup method. Following code will help you in creating custom lookup using SysTableLookup with multiple data sources.
public void lookup(FormControl _formControl, str _filterStr)
{
SysTableLookup sysTableLookup;
Query query;
QueryBuildDataSource qbds1, qbds2;
;
sysTableLookup = SysTableLookup::newParameters(tablenum(table1),_formcontrol);
query = new Query();
qbds1 = query.addDataSource(tablenum(table1));
qbds2 = qbds1.addDataSource(tablenum(table2));
qbds2.joinMode(JoinMode::InnerJoin);
qbds2.addlink(fieldNum(table2, field1), fieldNum(table1, field1));
// if relation already defined in AOT between table1 & table2 then comment above statement use below one.
//qbds2.relation(true);
qbd1.addRange(fieldnum(table1, field1)).value("value");
qbd2.addRange(fieldnum(table2, field1)).value("value");
sysTableLookup.addLookupfield(fieldnum(table1, field1));
sysTableLookup.addLookupfield(fieldnum(table1, field2));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Comments
Post a Comment