In one of the previous posts we discussed how to override methods on form data source fields (AX 7. How to override form data source field methods without overlaying.). Today we will talk about form controls.
In AX 7 we have a bunch of events to subscribe on a form control level:
Let’s change a lookup, because it is a quite common customization.
/// <summary> /// Adds a lookup to the <c>CustAccount</c> control on <c>SalesTable</c> form. /// </summary> /// <param name="_sender">The source of the event.</param> /// <param name="_e">Arguments of the OnLookup event.</param> [FormControlEventHandler(formControlStr(SalesTable, CustAccount), FormControlEventType::Lookup)] public static void SalesTable_CustAccount_OnLookup(FormControl _sender, FormControlEventArgs _e) { SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), _sender); Query query = new Query(); sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum), true); sysTableLookup.addLookupfield(fieldnum(CustTable, Party)); sysTableLookup.addLookupMethod(tableMethodStr(CustTable, nameAlias)); sysTableLookup.addLookupfield(fieldnum(CustTable, OurAccountNum)); QueryBuildDataSource qbds = query.addDataSource(tablenum(CustTable)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); FormControlCancelableSuperEventArgs ce = _e as FormControlCancelableSuperEventArgs; //cancel super() to prevent error. ce.CancelSuperCall(); }
Please note that execution of original lookup should be cancelled by FormControlCancelableSuperEventArgs.CancelSuperCall() otherwise AX will throw an error “More than one form was opened at once for the lookup control.”
Hi,
Even after calling cancel super, I am getting the error.
Its hard to say what are you doing wrong without seeing your code. Also please consider asking this question on community forum https://community.dynamics.com/ax/f/33 It’s easier to discuss question there, than doing it in blog comments.
Hi,
I need to override form control method textChange() for itemId in salesline.
Can I use same approach to override form control method instead of form datasource field?
Thanks
It may work, just try!