Friday, May 19, 2023

How to extend lookup method and apply query range on the standard MS form X++

Hi folks

In this blog, I am going to explain how lookup control on the standard form can be overridden. 

Requirement:

I got the requirement from the customer where in user wants to select Operating unit of type "Department" from the drop down list on the custom fast tab which contains the custom fields on the grid.

Since, Operating units are shared across mutiple legal entities therefore lookup control will display Departments across all companies.

Solution: 

Create a class that will handle the logic of overriding the lookup control and applying the range of Operating unit of type "Department" on the lookup. This class is being called on the Form event handler on the lookup control

Form control lookup override extension class:

 public class DemoLogisticsPostalAddressFormExtensionOverrides  
 {  
   protected void new()  
   {  
   }  
   public static DemoLogisticsPostalAddressFormExtensionOverrides construct()  
   {  
     return new DemoLogisticsPostalAddressFormExtensionOverrides();  
   }  
   public Common lookupReference(FormReferenceControl _formReferenceControl)  
   {  
     return OMOperatingUnitHelper::operatingUnitLookup(_formReferenceControl,     OMOperatingUnitType::OMDepartment);  
   }  
   public Common resolveReference(FormReferenceControl _formReferenceControl)  
   {  
     // Do not call super since we're providing our own disambiguation logic.  
     return OMOperatingUnitHelper::operatingUnitResolve(_formReferenceControl, OMOperatingUnitType::OMDepartment);  
   }  
 }  
Form datasource event handler class:

Create a form datasource event handler class for the control on which Departments will be displayed.

Create datasource post event handler initialize method

 public class DemoLogisticsPostalAddressFrmEventHandler  
 {  
   [FormDataSourceEventHandler(formDataSourceStr(LogisticsPostalAddress, DemoDeliverySettings), FormDataSourceEventType::Initialized)]  
   public static void DemoLogisticsPostalAddress_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e)  
   {  
     var overrides = DemoLogisticsPostalAddressFormExtensionOverrides::construct();   
     
     _sender.object(fieldNum(DemoShiftDeliverySettings, Department)).registerOverrideMethod(methodStr(FormDataObject, lookupReference),  
       methodStr(DemoLogisticsPostalAddressFormExtensionOverrides, lookupReference), overrides);
       
     _sender.object(fieldNum(DemoShiftDeliverySettings, Department)).registerOverrideMethod(methodStr(FormDataObject, resolveReference),  
       methodStr(DemoLogisticsPostalAddressFormExtensionOverrides, resolveReference), overrides);  
   }  
 }  

No comments:

Post a Comment

Enable and Disable Vendor invoice button on PO list and details page X++

Hi folks, This blog will be useful where vendor invoice process is required to be controlled based on certain conditions. Requirements: Proc...