Override Lookup AX7 & D365FO


Override Lookup AX7 & D365FO



Here is a small example to override lookup.


copy the lookup event handler of the field and  paste the event into any class




/// <summary>
    ///
    /// </summary>
    /// <param name="sender">receiving value in parameter</param>
    /// <param name="e">receiving value in parameter</param>
    [FormControlEventHandler(formControlStr(PayrollEmployerTaxRegion, Overview_StateId), FormControlEventType::Lookup)]
    public static void Overview_StateId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
           /// write your lookup code here

if the control or field already has a lookup to we need to cancel parent lookup execution otherwise we will get an exception.

below code you can use to cancel parent lookup ---
        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        //cancel super() to prevent error.
        ce.CancelSuperCall();
      }


Here is the complete code sample 


/// <summary>
    ///
    /// </summary>
    /// <param name="sender">receiving value in parameter</param>
    /// <param name="e">receiving value in parameter</param>
    [FormControlEventHandler(formControlStr(PayrollEmployerTaxRegion, Overview_StateId), FormControlEventType::Lookup)]
    public static void Overview_StateId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysTableLookup      sysTableLookup  = SysTableLookup::newParameters(tableNum(LogisticsAddressState), sender);
        Query               query           = new Query();

        // Filter lookup to only show US states
        query.addDataSource(tableNum(LogisticsAddressState)).addRange(fieldNum(LogisticsAddressState, CountryRegionId)).value(LogisticsAddressCountryRegion::findByISOCode(SysCountryRegionCode::countryInfo(curext())).CountryRegionId);

        // Sort the lookup by state Id
        query.dataSourceTable(tableNum(LogisticsAddressState)).addOrderByField(fieldNum(LogisticsAddressState, StateId), SortOrder::Ascending);

        // Add fields
        sysTableLookup.addLookupfield(fieldNum(LogisticsAddressState, StateId));
        sysTableLookup.addLookupfield(fieldNum(LogisticsAddressState, Name));

        // Run lookup
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;

        //cancel super() to prevent error.
        ce.CancelSuperCall();
    }


Support Faryal's Cusine


Card Pattern in Grid D365FO & AX 7



Card Pattern in Grid  D365FO & AX 7


Yesterday, One of my team member had task to show data in Grid in Card Style like work space, in the initial state we were trying to create work space tile dynamically but no luck.


After spending hour i found an page with pattern design Card.



Here are the some steps to achieve the below task. 




Step-1 Create Custom form and data-source and Grid,

Step-2 apply the patter of list page on design node of the form and follow the design pattern instruction.



Step-3 Now select the grid and change the following  properties of Grid.
  1. Style= List
  2. Extended Style= CardList


Step-4 Now add the Group in the grid and apply the pattern of business Card.

Step-5 Follow the instruction of business card design pattern and add the required field.




Step-6 Create Display menu item set object properties with you newly created form. 
Step-7 Create menu extension and drag the display menu item on it
Step-8 Last steps to perform build and sync.


Now login on you D365FO instance and verify the form...

for me its working fine, kindly check the below screenshot for reference.




Please feel free to contact me if you are facing any issue during implementation of this blog.



Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...