I'm trying to create a simple lookup in a field of a datasource in a form.
The tables and related forms are BankAccountTable.
1.- Added new field BullCust (extends EDT CustAccount) and field group to new extension BankAccountTable.MyExtension.
2.- Created new form extension BankAccountTable.MyExtension and added new group to form.
This works OK. But now I want a simpler lookup. In Ax2012, I would override BankAccountTable\Datasources\BankAccountTable\BullCust\Lookup method, with something like this:
public void lookup(FormControl _formControl, str _filterStr)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(ExcEC_DocuTypeTable), _formControl);
queryBuildDataSource = query.addDataSource(tableNum(CustTable));
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupField(fieldNum(CustTable, Party));
sysTableLookup.addLookupField(fieldNum(CustTable, RecId));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
In Ax7 this doesn't work anymore. Tried this approach (based on https://ievgensaxblog.wordpress.com/2016/05/01/ax-7-how-to-override-form-data-source-field-methods-without-overlaying/):
3.- Created class that manages lookup:
public class BullFormBankAccountTable_Handler
{
public static BullFormBankAccountTable_Handler construct()
{
return new BullFormBankAccountTable_Handler();
}
public void BankAccountTable_BullCust_OnLookup(FormDataObject _formDataObject, FormControl _formControl, str _filterStr)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(BullDocuTypeTable), _formControl);
queryBuildDataSource = query.addDataSource(tableNum(CustTable));
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupField(fieldNum(CustTable, Party));
sysTableLookup.addLookupField(fieldNum(CustTable, RecId));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
}
4.- Created class extension that subscribes and links apropiated events:
[ExtensionOf(formStr(BankAccountTable))]
final public class BullFormBankAccountTable_Extension
{
[FormDataSourceEventHandler(formDataSourceStr(BankAccountTable, BankAccountTable), FormDataSourceEventType::Initialized)]
public static void BankAccountTable_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e)
{
var overrider = BullFormBankAccountTable_Handler::construct();
_sender.object(fieldNum(BankAccountTable, BullCust)).registerOverrideMethod(methodStr(FormDataObject, lookup),
methodStr(BullFormBankAccountTable_Handler, BankAccountTable_BullCust_OnLookup), overrider);
}
}
And no result. I've debugged and BullFormBankAccountTable_Extension.BankAccountTable_OnInitialized() is properly called. But resulting lookup is the standard one, not the mine one. Any ideas or example about how should this be performed?
(PS: version Ax7 Platform Update 9)
Try only with FormControl parameter:
I checked it and works.