Followers

5 March 2016

Custom Reference Group in Dynamics AX

Microsoft Dynamics AX 2012 introduced a new form control type as Reference Group

So go to your form data source and find the reference field for which you want to perform the lookup. override the lookupReference method.

    We can construct a query,add data sources and ranges  and then pass it to SysReferenceTableLookup, like the below code :


public Common lookupReference(FormReferenceControl _formReferenceControl)
{
    SysReferenceTableLookup     sysRefTableLookup;
    Query                       lookupQuery = new Query();
    QueryBuildDataSource        lookupQueryDataSource;
 
    // Construct the SysRefTableLookup object
    sysRefTableLookup = SysReferenceTableLookup::newParameters(tableNum(MyTable), _formReferenceControl)
 
    // Add the field list that will be displayed on the lookup form
    sysRefTableLookup.addLookupfield(fieldNum(MyTable, MyFirstField));
    sysRefTableLookup.addLookupfield(fieldNum(MyTable, MySecondField));
 
    // Construct the query's data source
    lookupQueryDataSource = lookupQuery.addDataSource(tableNum(MyTable));
 
    // Add ranges to the query data source
    lookupQueryDataSource.addRange(fieldNum(MyTable, MyFirstField)).value(queryValue(''));
    lookupQueryDataSource.addRange(fieldNum(MyTable, MySecondField)).value(queryNotValue(''));
 
    // Pass the query to the lookup object
    sysRefTableLookup.parmQuery(lookupQuery);
 
    return sysRefTableLookup.performFormLookup();
}