How to create lookup in form data source field in D365FO
Creating lookup on form is very common requirement for a better user experience. In this blog post, I will discuss about how to create lookup in form data source field using in D365FO. I will create this using extension approach in Microsoft Dynamics 365 for Finance and Operations.
Previously, I have created a post in which I have discussed about how to create lookup in D365FO using x++ in which the event handler method of OnLookup event of FormControlString is implemented. But, one of our senior community member mentioned that creating lookup in form data source field is a better approach than handling it on the FormStringControl.
According to the IEVGEN’S AX BLOG, there are many disadvantages of using lookup on FormControlString. They are as follows:
- If user add add new control using personalization, the overridden logic would not any more.
- If several controls are refereing to the same data source, the code and work have to be duplicated.
I had also uploaded a video tutorial on my YouTube channel. In that video, I have discussed a very easy and best approach to create form, automatic lookup and implement clicked() method of button in Microsoft D365FO. Sometimes, it may not fulfill your complex business requirement.
So, I have shared a video tutorial on how to create lookup in form data source field in D365FO. And in this tutorial, I will discuss about how to create lookup in form data source field in D365FO. You can also see the video.
- Create a table and name it as Moeen_LookupTable
- Add a string field and name it as PersonnelNumber and set StringSize as 20
- Create a form and name it as Moeen_LookupForm and use your custom table we have created in previous step as data source of form
- Set the pattern of form as Dialog – Basic
- Add the Group and set it’s pattern as Fields and field groups
- Add the PersonnelNumber field from data source to the Fields and field groups
- Set the Auto declaration to Yes for the PersonnelNumber FormControlString
- Add ButtonGroup and add two buttons in it
- Override the clicked() method of buttons
- Add the code in each button from here
- Set the Save record of property to No for both buttons
- Create two Classes with following names:
- Add the code in each class from here
- Build and synchronize the project
- Run your form and test your lookup
See the video: Click here
Download the complete project: Click here
Download the code: Click here
Blog: Click here
YouTube: Click here
GitHub: Click here
If you found any ambiguity or better solution. Please let me know. Moreover, if this helps you, please comment and share.
Don’t let small minds convince you that your dreams are too big.