Filtering Lookup by Relation in Dynamics 365 for Operations

by | Updated January 3, 2018 | Development, Dynamics 365 for Finance and Operations

Last time I showed how to add filtering capabilities to your lookup using the DataInteractorFactory class. This time I intend to show how to extend filtering capabilities to support lookups where there is more than one key field on the target table.

Let’s say we have a table, SSISplitBillingTable, that contains split billing codes for a customer. The primary key for this table would then be the combination of the SplitBillingCode and AccountNum.

Combination of SplitBillingCode and AccountNum

This also implies that each customer may have multiple SplitBillingCodes. Because we want to identify a default code for each customer, we will add a foreign key to CustTable.

Add foreign key to CustTable

And a table relation to SSISplitBillingCode to enable the lookup.

Add split billing code to lookup

When we click the drop-down to select a Split billing code from the CustTable form, we are presented with too many records. The intention is to allow the user to select only Split billing codes that are associated with the current CustTable record. As you can see, the list contains 2 records for the current customer, C0020, and one for customer AA.

split billing code associated with CustTable record

It was at this point that I must admit I was a little confused. I had assumed that if I put both fields in the table relation that my list would be properly filtered, but apparently, I would be forced to write a little code to make this work. I knew I didn’t want to add a lookup method to every form that would contain this field because that requires too many modifications and doesn’t do anything to prevent future problems. Instead, I was going to see if I could modify the DataInteractorFactory class. It was here I learned something new.

My approach was to explore the DataInteractorTarget owned by the DataInteractorFactory class. Among other things, this class identifies the field, control, and table relation involved in the lookup. A little investigation led me to the BoundRelation class, and the realization that my scenario was already supported.

Inside the applyFieldDependenciesToQuery method, the BoundRelation class sets up the query used to perform the lookup. It does this by iterating through the collection of dependent fields, adding each field value as a range on the query. The problem was that my dependent fields collection was empty. The reason the collection was empty could be found in the processDictRelation method. This method iterates over the lines in the table relation until it finds the primary key field. Each field it encounters before it is found is added to the dependent field list.

 

This means that to filter our lookup to only those records with a matching AccountNum, we need only reorder the lines in our table relation.

Filtering_Mark5

Now when we use the lookup the results are properly filtered.

Filtering_Mark6

Related Posts

4 Comments

  1. Denis

    the first question when you show this to user or consultant will be to remove account Id field (or at least change its position) – first field in lookup should be what we are selecting. did you find the way to achieve this without programming?

  2. Brandon Carmichael

    Hello Denis:

    After talking with Mark, he did not find a way to achieve this without programming. That said, not sure if this is or is not possible without programming – it was never our goal to achieve this without programming.

    Thanks,
    Brandon

  3. DP

    Hi ,
    I need to lookup the cost center dimension values in string edit control in a new table in D365 for operations
    Any ideas how to do ?

  4. Brandon Carmichael

    Hello DP,

    Thanks for reading and for the comment. Unfortunately we’ve not had a need for that type of lookup, so I don’t have a short answer for you without putting some hours into testing. It sounds like a great future blog post!

    Thanks,
    Brandon

Submit a Comment

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

Upcoming Events

february

03feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 2 – Platform

10feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 3 – Implementation Partner

11feb11:00 am12:00 pmConfab with Stoneridge - Livestream - Live Agents, Power Virtual Agents, Omnichannel – Oh My!

16feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 4 – Cost

24feb10:00 am11:00 am5 Campaigns Manufacturing Marketers Don’t Want to Miss

25feb11:00 am12:00 pmConfab with Stoneridge - Livestream - Surfing Through the Dynamics 365 Wave 1 2021 Release

march

03mar10:00 am10:30 amThe Modern Manufacturer - MRP vs. MPS – What, When and How

03mar2:00 pm2:30 pmLot Management Best Practices for Batch Manufacturers

10mar10:00 am10:30 amEnhancing the Customer Experience and Driving More Business with Dynamics 365 Customer Service

10mar2:00 pm2:30 pmThe Five Steps to Managing Sales Tax for Manufacturers

11mar11:00 am12:00 pmConfab with Stoneridge - Livestream - Power Apps Component Framework Power Hour

17mar10:00 am10:30 amThe Modern Manufacturer: Pro Tips for your Finance Team

24mar10:00 am10:30 amUnlock the Potential of Digital Marketing with Dynamics 365 Marketing

25mar11:00 am12:00 pmConfab with Stoneridge - Livestream - The Four Keys to Choosing the Best ERP or CRM Solution

31mar10:00 am10:30 amThe Modern Manufacturer: Keys to Reporting Success

31mar01aprFinancial Reporting w/ Account Schedules for Dynamics 365 Business Central

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