The Customer lookup fields offer great possibilities and we missed it in earlier versions of Dynamics365.
But sometimes, the out-of-the-box setup offers to much information.
For those who don’t know what the Customer field type is, here is the Microsoft definition
“The Customer field allows for a single reference to either an account or a contact record. These lookups are available for the Opportunity, Case, Quote, Order, and Invoice entities. These entities also have separate Account and Contact lookups that you can use if your customers are always one type. Or you can include both instead of using the Customer lookup.”
Without any customization, the default behavior of this fields looks like this.
A common requirement we have all implemented at least once in our life, is to limit the default parentcustomer field on contact so only accounts can be picked as a value. We basically want to filter customer lookup fields on a specific entity type.
The old way…
Almost every time, I see that the addPreSearch in combination with the addCustomFilter method is used to enforce this functionality.
This could look like:
This works fine, as you are no longer able to see any contacts in the contact section. The filter condition made sure no results are displayed.
However, the contact section is still there and sticks out like a sour thumb!
Users start to ask why this is there and why no results are shown.
They are still able to create a new contact, but it will never show up in this view.
So, while this approach is not wrong, it raises some questions.
The better way…
A better approach would be to just hide the contact section using the setEntityTypes method.
Which looks like:
This will result in neater user experience and to be honest, it’s also a bit less work for us developers 😉
So win-win…
Here is the final result
When clicking on the “1 type of record” link, we can see there is no longer an option to select the contact views
As you can see, we’re now able to successfully filter customer lookup fields.
Hi, thanks for the post. but I am writing to point out one issue in your blog post. "Text Color", man Black text color on a white background is the best combo, whereas you are using some middle gray which is hard to read and not user-friendly. people come on the blogs to get informtion but after trying To do So I got a headache, its really hard to read. I don't have any bad intention but just wan tit to be more eye catche. Never MInd :) Happy Blogging, keep it up to bring the good stuff. Sincere Reader.
H
[…] an extensible enterprise business application platform, you can of course get a developer to write some JavaScript to change the default behaviour of the lookups that bother you. As for me personally, I always like […]
hi ram, that's strange?! I cannot seem to reproduce this behavior. When clicking the 'New Record' button I can only create a new account record (as expected).
If click new Record it is showing Both entitites. can you pls help me on this?
You can disable the "Change View" option however you cannot hide or remove it from the lookup control. Navigate to Settings -> Customization -> Customize my System -> Expand Entities -> Select the entity -> Open the Form -> Double click on the field for which you need to disable the change view Once the Field properties page is open -> Scroll down to Field properties section and select the View selector as "Off" However, this option is not available on 'customer' lookup fields :-( So, I don't think it's possible with an out of the box setting
how to disabled change view
Hi Thanks heaps - works a treat Pete
[…] bericht Filter Customer Lookup fields in Dynamics 365 verscheen eerst op […]