Creating a Default Lookup Form with Filter in Dynamics AX

by | Updated August 15, 2016 | Development, Dynamics AX

When working in Microsoft Dynamics AX have you ever found yourself reusing or copy/pasting the same code to create the same lookup over and over to custom forms and/or report parameters? Have you ever been asked if you could modify the lookup form to allow for filtering?  If the answer is yes, then you may be interested in creating a default lookup form with filter in Dynamics AX.

The standard lookup forms are usually nothing more than a grid. However, you can get as creative as you want with them to allow for fact showing when a record is selected or whatever else you can imagine that you would want to see on your lookup form. (A great example of a very functional and informative standard AX lookup form is the HCMWorkerLookup form.)

The following is a simple example of how to create a lookup form with the option to filter with prepopulated combo box values.

Create Extended Data Type

  • Create a new EDT type of string.
  •  Name: DinosaurName
  •  StringSize: 20

Project Default Lookup

Create Enum

  • Create a new base enum
  • Name: DinosaurMealPlan
  • Add 3 new elements
  1. Name: All
  2. Name: Herbivore
  3. Name: Carnivore

Project Default Lookup Examples

Create table and fields

  • Create new table
  • Name: Dinosaurs
  • Add 2 new fields
  1. Create Field type of type string
  • Name: DinosaurName
  • EDT : DinosaurName

2. Create field of type enum

  • Name: DinosaurName
  • EnumType : DinosaurName

Project Default Lookup Examples

Add data to table

We need some data to play with so insert the following values into the newly created Dinosaurs table.

Table

Create a Form

The first thing you need to do is to create a basic form.

Project Default Lookup Designs

Set form design properties

Now we need to set the design properties on the form so it behaves like a standard lookup. The following design properties need to be change.

  1. Frame: Border
  2. AlwayOnTop: Yes
  3. HideToolbar: Yes
  4. Style: Lookup

Add form groups

We want our grid to be separated from the drop down we will use the fileter the data. So we need to add two groups.

  1. Group will contain a grid
  • Name: MainArea

2. Group will contain our combo box

  • Name: Filter
  • Top: Top edge (this will allow our combo box to be displayed on the top left of the form)

Project Default Lookup Design

Add a Grid to design

  • Add grid to our group “MainArea”
    • DataSouce: Dinosaurs

Project Default Lookup Examples

Add a combo box to design

  • Add combo box to our group “Filter”
    • Name: cmbDiet
    • AutoDeclaration: Yes
    • EnumType: DinosaurMealPlan

Project Default Lookup Group Filter

Add form Data Source(s)

Drag the Dinosaurs table we created earlier to the data sources object on the form.

Project Default Lookup Example

Set form Data Source(s) Properties

The data source(s) properties need to be update as listed below.

  1. AllowEdit: No
  2. AllowCreate: No
  3. AllowDelete: No
  4. InsertAtEnd: No
  5. InsertIfEmpty: No

Add data source field to form grid

Now that we have our data source added let add one of its fields to our grid.

  1. Drag the filed DinosaurName to the grid on the form
  2. Update properties on newly add grid control
  • AutoDeclaration: Yes

Project Default Lookup Data Dictionary

Modify Form Methods

Now we need to modify the forms methods to give the functionality of a lookup form.

Init method

Now we need to override the forms init() to tell the form which control will be used as the selected value.

Run method

We want to override the forms run() to allow filter to behave properly in the AX environment

 

Create form method

We will create a new method called updateQuery() to handle changes to our data sources query when the filter criteria changes in our combo box.

Modify data source method

We will override the Dinosaurs data source method executeQuery() to allow for our updates to the querys data sources ranges.

This will utilize the updateQuery() that we created in the form.

 

Modify Form Control methods

We need to override the method selectionChange() on the combo box with the following code.

Whenever a user changes their selection in the combo box it will update our query and thus change the look form to reflect their selection.

Add as default lookup from for Extended Data Type ( EDT )

Ok, so now we are at the whole reason I started this article. I initially was not aware that you could assign a created lookup form to an EDT. Wow? Who cares, right? We should care because this allows us to better follow the DRY (Don’t repeat yourself) principle. Which of course helps with maintainability and reusability.

This comes in really handy when you are doing data contract classes for reports. Especially if you are doing a lot of custom reports that are using the same EDT as a parameter.  This allows you to reuse the lookup form without much extra code if any. Also if you don’t require any further complexity to the report parameters, then it also saves you from having to create a UIBuilder class to allow lookups for the parameters.

To set the lookup form as your lookup for the EDT set the following property on the selected EDT.

  • FormHelp: DefaultLookup

Call form from a lookup event

You can also call this from if you are overriding a lookup method on a form.

Below is an example of how you can accomplish this.

 

Now go implement the lookup form that was created and it should look like the images below.

Filter choices

Filter Choices

Carnivore filter selected

Filter selected

And there you have your lookup form with filter in Dynamics AX.

Related Posts

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events

september

01sep10:00 am10:30 amEnsuring Quality and Compliance for Batch Manufacturers in Life Sciences

01sep12:00 pm12:30 pmIs it Worth It to Move to the Cloud? A Look at Considerations for Current Agribusinesses Using Dynamics GP

01sep2:00 pm2:45 pmWhat’s New in Dynamics 365 Finance and Supply Chain

09sep11:00 am12:00 pmConfab Live with Stoneridge – Data Strategy and Reporting – Mining Decision Making Insights

15sep10:00 am11:00 amSolving the Biggest Challenges in Agribusiness Through Innovation and Technology

22sep12:00 am12:30 pmSimplifying Payroll and HR Management with ADP Workforce Now

22sep10:00 am10:30 amStreamlining Batch Manufacturing with Technology

22sep2:00 pm2:30 pmProcess Automation for Microsoft Dynamics D365 for Business Central, Finance and Operations and GP

23sep11:00 am12:00 pmConfab LIVE with Stoneridge - Riding the Wave 2 Release – Key Features Coming to Dynamics 365 this October

27sep(sep 27)9:00 am15oct(oct 15)11:00 amDynamics 365 Finance & Supply Chain Development Training - Online Workshop

29sep10:00 am11:00 amTop Five Reasons Why NOW is the Right Time to Move from Salesforce to Dynamics 365 Customer Engagement

29sep12:00 pm12:45 pmUnderstanding Job Costing and Tax Management in Business Central

29sep2:00 pm3:00 pmDigitalizing Horticulture & Agriculture - How to Sell Plants Online and Simplify Business Management

30sep12:00 pm4:00 pmSecurity and Permissions Training for D365 Business Central or Dynamics NAV

october

27sep(sep 27)9:00 am15oct(oct 15)11:00 amDynamics 365 Finance & Supply Chain Development Training - Online Workshop

06oct10:00 am10:30 amPreview of D365 Business Central Fall Release Features and Functionality

06oct12:00 pm12:30 pmInsider's Guide to New Features Available in the Fall Release of D365 Finance and Supply Chain

07oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Technical

21oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Functional

26oct(oct 26)9:00 am28(oct 28)5:00 pmStoneridge Connect Leadership and Community Conference

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X