[X++] Lookup on ReferenceGroups
When adding a Field to a table by foreign key RecId and later adding this field to a form, AX automatically created a FormReferenceGroup
.
Let's say we want to override the lookup behavior because we need to filter the records displayed in the lookup.
On a normal form control one would simply override the lookup method and use SysTableLookup
to build the desired lookup.
With a FormReferenceGroup
it behaves different.
Override the lookupReference
method on the Data Source level of the form like this:
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(LogisticsLocationRole), _formReferenceControl);
Query query;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
LogisticsLocationRole selectedRecord;
sysTableLookup.addLookupfield(fieldNum(LogisticsLocationRole, Name));
sysTableLookup.addLookupMethod(tableMethodStr(LogisticsLocationRole, description));
sysTableLookup.addLookupfield(fieldNum(LogisticsLocationRole, Type));
query = new Query();
qbds = query.addDataSource(tableNum(LogisticsLocationRole));
// Filter:
qbr = qbds.addRange(fieldNum(LogisticsLocationRole, IsContactInfo));
qbr.value(SysQuery::value(NoYes::Yes));
qbds.addSortField(fieldNum(LogisticsLocationRole, Name));
sysTableLookup.parmQuery(query);
// Now here is the special part, it returns the selected record:
selectedRecord = sysTableLookup.performFormLookup();
return selectedRecord;
}