/ Dynamics

# [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;

query       = new Query();
// Filter:
qbr.value(SysQuery::value(NoYes::Yes));

sysTableLookup.parmQuery(query);
// Now here is the special part, it returns the selected record:
selectedRecord = sysTableLookup.performFormLookup();

return selectedRecord;
}

#### Robin

Software Engineer / Application Developer

[X++] Lookup on ReferenceGroups