Showing posts with label LookUp. Show all posts
Showing posts with label LookUp. Show all posts

Simple Look Up D365FO - AX-2012


Simple Look Up D365FO - AX-2012


Simple Look Up
Today we learn Simple Look Up in just 4 Step
Step: 1
Create a form Then add StringEdit Control in Design and override the lookup method.




Step: 2
Copy Paste this Code in the lookup method




Step :3
Create a AOT Query . In this tutorial my query name is  LookUpFormQuery 




Step :4
Compile Complete Project and Run the form




Support Faryal's Cusine


How to override form control Lookup using extensions. D365FO

How to override form control Lookup using extensions. D365FO



In D365FO we have a bunch of events to subscribe on a form control level:





right click on lookup event of control to subscribe the event and paste in class.



[FormControlEventHandler(formControlStr(PayrollEmployerTaxRegion, Overview_StateId), FormControlEventType::Lookup)]
    public static void Overview_StateId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
                  // write your logic here
    }

Now to cancel parent event, D365FO provide a class FormControlCancelableSuperEventArgs

You can cancel the parent(Original event with below code)

        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;


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

// Here is the complete code sample to override form lookup and cancel the original code.


[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


Form Look Up



Form Look Up

Today, we Learn how to create Form Look Up
Step: 1
Create a Project and Add two forms.




Step :2
  • Add HCMWORKER table in SL_LookUp_Form Data Source.
  • Add Grid and Drag and Drop the two fields on the grid
Step :3
Set Personnel Number field Property : set as Auto Declaration to YES


Step :4
Now Compile the complete project then run the form.




Step :5
Now right click on Design node(not Designs) and set style property to LookUp.



Compile and Run again Form will look like the below image.



Step :6
Now override the init method of SL_Lookup_Form .



copy paste the below code.



Step:7
Now Select SL_First_Form
Create a Method with name of CustomLookup and copy paste the below code.




Step: 8
  • Add StringEdit Control in the Design.
  • After adding the StringEdit Control override the lookup method.
  • Copy paste the below code.


Step :9
Compile project and run SL_First_Form




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...