Friday 9 November 2012

SysReferenceTableLookUp class for reference group

There is a nice class with name “SysReferenceTableLookUp “ that I found during the analysis of reference control that has just been introduced in Ax 2012. The class is helpful for customizing lookup of a reference control.

Why a different class for reference control?

That’s a good question. The simple answer of this question is reference control behaves in a different way than normal control. It shows a different value on the UI to the user but it saves different value at the back-end. If you google it for analyzing the msdn view about this class, you would find definition something like “A sibling of SysTableLookup that is used to generate Grid-style custom lookups for Reference Controls. According to my point of view, if you don’t use this class in case of Reference control and drag the RecId foreign key directly on the Form and override the lookup in the normal way, then on selecting the value from lookup, it would show the RecId to the user on UI.

Ok, how can I implement this?

You need to override the lookup reference method of the control or the foreign key field on the data source level. This method returns a table record and it is not void as SysTableLookup class.
publicCommon lookupReference(FormReferenceControl _formReferenceControl){
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(testTable), _formReferenceControl);
Query testQuery;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
TestTable selectedRecord;
// Display the coulmns fields in the lookup form.
sysTableLookup.addLookupfield(fieldNum(TestTable, TestColumn1));
sysTableLookup.addLookupfield(fieldNum(TestTable, TestColumn2));
// Create a custom Query
testQuery= new Query();
qbds = lookupQuery.addDataSource(tableNum(TestTable));
qbr = qbds.addRange(fieldNum(TestTable, TestColumn1));
qbr.value(SysQuery::valueNot(1));
qbds.addSortField(fieldNum(TestTable,EarningCode));
sysTableLookup.parmQuery(testQuery);
selectedRecord = sysTableLookup.performFormLookup();
return selectedRecord;
}

No comments:

Post a Comment