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…
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 😉
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.