How to use a View to Simplify Working with Query Classes in Dynamics AX

by | May 16, 2016 | Development, Dynamics AX

Have you ever used a View to simplify working with Query classes in Dynamics AX? I have worked on a couple projects where my lookups were not working quite like I wanted them to when working with the Query classes. The problems specifically happened when I wanted to see data from a child table that was two, three or four levels deep. The lookup wouldn’t run or the data coming back into the lookup form would say ‘Unknown’. I thought to myself, it would be nice if the data I wanted to see was in one table and I would not need to do any joins using the Query classes. This is when I realized that using a custom View created in the AOT would be handy.

Let’s say I wanted to see data related to Project Contracts and their Customers that are associated with Projects in my lookup. (Physical table and field names in parentheses):

 

The customer name lives in DirPartyTable so this will require joining three tables to get to it:

To create the view in the AOT, you can choose a table based one or a query based one. If you want a query based one, then you create the query in the AOT first and then select it using the Properties window of the view object. This is an example of the CustBankAccountCrossCompanyView that is query based:

Chris R_Cust Bank Account

 

I used a table based query for this solution. The ProjTable will be the parent table and will join the other three tables I listed above. The view looks like this:

AOT Data dictionary views

 

Now that my view is defined in the AOT, I can now test it in a job or a custom lookup with X++. The following is a job that displays the data for a certain Customer number:

Note: There is only one QueryBuildDataSource required since the view joins the underlying tables behind the scenes.

 

Here would be a similar example of the job code in a method that would be used in a lookup filtering on a Customer number:

I hope this technique helps if you run across the same problems joining multiple QueryBuildDataSource objects when you need data from child tables.

 

Related Posts

0 Comments

Submit a Comment

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

Upcoming Events

july

29jun(jun 29)8:00 am06jul(jul 6)5:00 pmMicrosoft Dynamics GP Core Financials Bootcamp

07jul1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Bringing It All Together

08jul10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Planner

08jul2:00 pm2:30 pmHow Ag Retailers and Ag Coops Should Structure IT Resources for the Future

16jul11:00 am12:00 pmConfab with Stoneridge - Livestream - Business Intelligence Power Hour

22jul10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Material Handler

22jul12:00 pm1:00 pmImprove Field Service Delivery and Increase Customer Satisfaction

august

05aug10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Shipping / Receiving Department

05aug12:00 pm1:00 pmHow Ag Retailers Can Simplify Processing Equity Payments using Levridge

12aug10:00 am10:30 amWhy Levridge Grain? How to Achieve Efficient and Accurate Scale Tickets

12aug12:00 pm1:00 pmThe Three Paths to Dynamics 365 Finance and Supply Chain from Dynamics AX

13aug11:00 am12:00 pmConfab with Stoneridge - Livestream - Dynamics 365 2020 Wave 2 Review

19aug10:00 am11:00 amWhat is Levridge? An Overview of the Ultimate Ag Solution

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