Filter Contact Lookup Field Based on Account Lookup Field

Question Status

Verified
Eden Stafford asked a question on 27 Jan 2017 8:00 AM

Within an opp form I have two Account lookup fields (Bill To and End Client) and two Contact lookup fields (Bill To Contact and End Client Contact).  When a user goes to select the relevant contacts I want to limit the options they can choose from, only presenting them with the option to save Contacts that relate to their corresponding Account.  I believe related records filtering is the way to go, just not sure how to set appropriately.  Below is the part of the opp form that corresponds to these fields.  Any help would be appreciated. 

Reply
Verified Answer
Ryan Maclean responded on 27 Jan 2017 10:01 AM

Hi Eden,

This is really straightforward, and shouldn't require any code.  If you open the Field Properties for the Contact fields on your form (i.e. by double-clicking on them, or by highlighting them then clicking "Change Properties" on the ribbon), you can edit them by scrolling down to the "Related Records Filtering" on the Display tab of the properties modal.

In the related records filtering section, tick the box that says "only show records where" then select "Account in the first selector" and then "Company Name" in the second selector

Reply
Eden Stafford responded on 29 Jan 2017 8:21 PM

Hi Ryan,

Thanks, that helped clarify some confusion, but I'm left with some more in its place.  I followed your instructions for the End Client Contact field and configured it as below, which works great

However, when I go to do it the Bill To Contact field which is being drawn off the Customer field (labelled as Bill To), it's not working.  I go to select Customer (Accounts) (Opportunities) as shown below and again choose Company Name (Accounts) (Contacts) as I did for End Clients.

However, when I do that I get the Query Builder Error below

I'm not sure if it's because the Customer (again, labelled as Bill To) field is special in some way.  If you look in the image below, I've selected the same account for Bill To and End Client, yet the Bill To (again, technically Customer field) has some icon next to it.  Again, any help would be appreciated.

asd

Reply
Eden Stafford responded on 30 Jan 2017 12:03 AM

After some research I've identified that the Bill To field is of type "Customer", which may be why there is that icon and likely to be why I can't restrict the Bill To Contact field.  

Mahadeo's link to www.powerobjects.com/.../restrict-customer-lookup-to-accounts-or-contacts-in-dynamics-crm is actually relevant now, but not sure how to add the javascript to the form, doesn't seem to be working.  Might see if someone more technical in my company can help.

Reply
Suggested Answer
Ryan Maclean responded on 1 Feb 2017 7:46 AM

Hi Eden,

You are correct that it is because the Bill To field is of Type "Customer".  The Icon shows that the selected "Customer" is a Contact type, and this will cause conflicts when you try and restrict the Bill To Contact.  You could create a new "Bill To" field and make it a Lookup to Account, then use this to filter the Bill To Contact field.  You could then use a real-time workflow to populate your existing Bill To field with the Bill To Account.

This would save you needing to use any javascript

Reply
egcoons responded on 6 Oct 2017 5:19 PM

Hi Ryan, I was wondering, if one of my fields is in my business process flow, can I still do this ? I am trying to figure out how and I cant seem to do it. I cant find the ''Field properties'' box unless the field is in my form. If it is in my process I cant.. Help :(

Reply
Ryan Maclean responded on 11 Oct 2017 3:15 AM

Hi egcoons,

If you have the field in your BPF, then you could add it to your form in a hidden tab to apply the filter, and this should correlate to the field in the BPF

Reply
Verified Answer
Ryan Maclean responded on 27 Jan 2017 10:01 AM

Hi Eden,

This is really straightforward, and shouldn't require any code.  If you open the Field Properties for the Contact fields on your form (i.e. by double-clicking on them, or by highlighting them then clicking "Change Properties" on the ribbon), you can edit them by scrolling down to the "Related Records Filtering" on the Display tab of the properties modal.

In the related records filtering section, tick the box that says "only show records where" then select "Account in the first selector" and then "Company Name" in the second selector

Reply
Suggested Answer
Ryan Maclean responded on 1 Feb 2017 7:46 AM

Hi Eden,

You are correct that it is because the Bill To field is of Type "Customer".  The Icon shows that the selected "Customer" is a Contact type, and this will cause conflicts when you try and restrict the Bill To Contact.  You could create a new "Bill To" field and make it a Lookup to Account, then use this to filter the Bill To Contact field.  You could then use a real-time workflow to populate your existing Bill To field with the Bill To Account.

This would save you needing to use any javascript

Reply