AX – D365FO – Adding a Reference Group Lookup in Microsoft Dynamics AX 2012

In Microsoft Dynamics AX 2012, we can use a reference group to display the auto identification of a foreign key in a form. By using the ReplacementFieldGroup property of the reference group control, we could also choose to display a column instead of the auto identification of the foreign key.

Sometimes, we need to filter the content of the lookup. For example, when creating a record, we don’t want to display all the foreign keys. We want to display those who are matching certain criteria in a drop-down list.

Adding a Reference Group Lookup

On the form data source, locate the field that have the relation on the table where you want to perform the lookup on. Override the lookupReference method.

public Common lookupReference(FormReferenceControl _formReferenceControl)
{
SysReferenceTableLookup sysReferenceTableLookup;
Query query;
QueryBuildDataSource queryBuildDataSource;

// Add the fields that we want to display in the lookup form.
sysReferenceTableLookup = SysReferenceTableLookup::newParameters(tableNum(MyTable), _formReferenceControl);
sysReferenceTableLookup.addLookupfield(fieldNum(MyTable, MyFirstField));

query = new query();

// Build the query that we want to execute for the lookup.
queryBuildDataSource = query.addDataSource(tableNum(MyTable));
queryBuildDataSource.addRange(fieldNum(MyTable, MyFirstField)).value(queryValue('MyValue'));

sysReferenceTableLookup.parmQuery(query);

return sysReferenceTableLookup.performFormLookup();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s