A long time ago, I wrote a blog post explaining how to override form data source field methods. I skipped lookup, most popular method, because it did not work and logged a bug with MS hoping that it would be fixed soon. It took more time than I expected, but finally, it works!
Here is a small example how to override it. I’m going to use approach similar to previous post, full example is available on GitHub. Version I’m using is 7.3 PU13.
/// <summary> /// Handles events raised by <c>SalesTable</c> form. /// </summary> public class SalesTableEventHandler { /// <summary> /// Post event handler for <c>SalesTable</c> <c>SalesLine</c> Initialized event. /// </summary> /// <param name=“_sender”></param> /// <param name=“_e”></param> [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)] public static void SalesLine_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e) { var overrides = SalesTableFormExtensionOverrides::construct(); _sender.object(fieldNum(SalesLine, ItemId)).registerOverrideMethod(methodStr(FormDataObject, lookup), methodStr(SalesTableFormExtensionOverrides, ItemId_OnLookup), overrides); } } /// <summary> /// Contains methods which are used to override <c>SalesLine</c> data source field methods. /// </summary> public class SalesTableFormExtensionOverrides { protected void new() { } /// <summary> /// Constructs a new instance of <c>SalesTableFormExtensionOverrides</c> class. /// </summary> /// <returns> /// A <c>SalesTableFormExtensionOverrides</c> class. /// </returns> public static SalesTableFormExtensionOverrides construct() { return new SalesTableFormExtensionOverrides(); } /// <summary> /// Provides a lookup for the <c>InventTable</c> table /// </summary> /// <param name = "_callingControl"> /// The form string control object with which to perform the lookup. /// </param> public void ItemId_OnLookup(FormStringControl _callingControl) { SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), _callingControl); sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId)); sysTableLookup.addLookupfield(fieldNum(InventTable, NameAlias)); sysTableLookup.performFormLookup(); } }
As you may notice, signature of this method is different to signature of other methods, like validate or jumpRef. They accept FormDataObject as a parameter and lookup() accepts FormStringControl. It looks a bit inconsistent for me and we need to be extra careful here because you can register override method with any signature and get error in the run-time.