Filtered Lookups in 2011 – The Basics

Here’s a quick example of configuring a filtered lookup in 2011. 

In this scenario we want to be able to specify on an Opportunity who the Key Customer Contact is and when selecting this Contact we want the lookup to only offer up the Contacts attached to the Opportunity Customer.

1.  Let’s start by adding a Key Customer Contact field to the Opportunity entity / form.   Note: I love how much more fluent this process is in 2011…

a. Open the Opportunity form, click on the Customize ribbon tab and then click Form.  The Form Designer will launch.

image

b. Click the New Field button.  The New Field dialog will display.

image

c. Enter “Key Customer Contact” as the Display Name for your new field, select Lookup as the Type, and then select Contact as the Target Record Type.  Save and Close.  The field will be created and you will be returned to the Form Designer.

image

d. Your new Key Customer Contact field will appear in the Field Explorer list, drag it onto the Opportunity form

image

2.  At this point you might like to test things, so do a Save & Close of the Form Designer – you will be returned to the Opportunity form – click the All Customisations button on the Customize menu, and then refresh your browser window.

You should see your new Key Customer Contact field on the form… image

… and if you open its lookup  you should see the lookup displays all Contacts:image

3.  Ok, let’s now add the filtering.   Open up the Form Designer again (click on the Customize ribbon tab and then click Form). 

4.  Double-click on the Key Customer Contact field – the Field Properties dialog will display. 

5.  The relevant settings are in the last 2 sections – here’s how they will look initially

image

Note: there is no related record filtering going on.  The lookup dialog is set to display the “Contacts Lookup View” with other all other Contact views able to be selected and the Search box enabled.

6.  To enable the filtering we check the Only show records where: option in the Related Records Filtering section

image

7.  Next, we need to specify the source value from the Opportunity record to pass into the lookup and the destination field on the Contact entity on which to filter.  In our scenario the source value is the Potential Customer field on the Opportunity form and the field on the Contact on which we wish to filter is the Parent Customer field.

image

8. We need to decide whether this restricted list needs to be enforced or whether we are only doing this to be helpful and users should be able to optionally select a Contact from another Organisation.  In this scenario we want to enforce this so we uncheck the Allow users to turn off filter

image

9.  That’s it, you can save, publish and refresh to see the filtering in action.   Optionally, you can remove some of the clutter from the lookup dialog by disabling the display of the search box and turning off the View Selector

image

 

Here’s the end result – the Key Customer Contact lookup dialog now only offering the Contacts that are related to the Opportunity Customer:

image

 

Finally, some words of caution on this feature – the filtering  is only applied at run time as the user is populating the lookup field, it is not enforced after that point.  i.e. If having selected a Customer and a Key Customer Contact you then change the Customer field the Key Customer Contact field is not re-validated, CRM will allow the field to retain a value that would not be offered up by the filtered lookup.   

Think of this feature as a helper for your users, not as means of enforcing data integrity.  For that level of control you will need to consider some jscript or plugin code.

Advertisements

3 thoughts on “Filtered Lookups in 2011 – The Basics

  1. Huseyin

    Hi,
    Thanks for helpfull post.
    But if we want to filter the lookup according to any picklist value how we can do it? Do you have any idea?
    Thanks.

    Reply
    1. Gareth Tucker Post author

      Hi, have a read of my more recent post here.

      You’ll need to read the picklist value and then dynamically create a view and add that view to the lookup field. Similar to my 3rd scenario but simpler as you don’t need to do the oData query as the input data you want to use is on your form.

      Good luck!
      Gareth.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s