As Ievgen Miroshnikov explained in his old article https://community.dynamics.com/365/financeandoperations/b/ievgensaxblog/posts/d365foe-how-to-override-form-data-source-field-lookup-method, it is much better to override methods directly on a data source field than on its linked form controls.
I just want to re-iterate it and place here code snippets.
So, say we need to implement Lookup, JumpRef, and Modified methods for a custom field on CustInvoiceTable data source of CustFreeInvoice form. Implement these three aforementioned methods, e.g., directly in an extension to the form class.
- User can add new control using form personalization and this control won’t support overridden logic. It could be critical if you are restricting field lookup values or adding validations.
- One form could have several controls that refers to one data source field so you have to duplicate your code.
- Number of delegates are limited as well.
[ExtensionOf(formStr(CustFreeInvoice))] final class myCustFreeInvoice_Form_Extension { public void myAssignedBankAccountIdModified(FormDataObject _targetField) {
<logic> }
public void myAssignedBankAccountIdJumpRef(FormDataObject _targetField) {
<logic>}
// Different parameter here!
public void myAssignedBankAccountIdLookup(FormStringControl _callingControl) {<logic> }
public class myCustFreeInvoice_Form_EventHandler { [FormDataSourceEventHandler(formDataSourceStr(CustFreeInvoice, CustInvoiceTable), FormDataSourceEventType::Initialized)] public static void myCustInvoiceTable_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e) { FormRun eogFormRun = _sender.formRun(); FormDataObject eogCustomField = _sender.object(fieldNum(CustInvoiceTable, eogCustomField));
fdoEOGAssignedBankAccountId.registerOverrideMethod(methodStr(FormDataObject, jumpRef), formMethodStr(CustFreeInvoice, myAssignedBankAccountIdJumpRef), myFormRun); fdoEOGAssignedBankAccountId.registerOverrideMethod(methodStr(FormDataObject, lookup), formMethodStr(CustFreeInvoice, myAssignedBankAccountIdLookup), myFormRun); fdoEOGAssignedBankAccountId.registerOverrideMethod(methodStr(FormDataObject, modified), formMethodStr(CustFreeInvoice, myAssignedBankAccountIdModified), myFormRun); }
No comments:
Post a Comment