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();
}

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...