POWEROBJECTS

718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

When implementing Microsoft Dynamics CRM, you may have a requirement where you need to see a selection of records filtered to only records that are associated with an earlier user selection. Some of these filters can be achieved using out-of-the-box customizations. But in some cases, you might need to achieve this by implementing some simple customizations in CRM.

customizing

Today we’ll explain how to implement a custom filtered lookup using simple customizations. This can be used in any out-of-the-box or custom entity.

Let’s say that in the Account entity, when a user selects a primary contact, you want to show the user only those contacts associated to the selected parent account as a default view. This can be achieved by using some JavaScript in CRM. The following Xrm.Page.ui control object methods provide us a way to implement custom filtered lookups for a lookup field in CRM:

MethodFunctionality
addCustomViewAdds a new view for the lookup control
setDefaultViewSets the default view for the lookup control
getDefaultViewReturns the ID(GUID) value of the default view of the lookup control

The code snippet below does the magic of creating the custom filtered lookup:

Here are the steps to implement the custom filtered lookup for the primary contact in the account form:

  1. Add the above code snippet as a web resource in CRM.
  2. Navigate to Settings > Customization.
  3. Launch the working solution, or if you do not have one, either create one or click on Customize the System.
  4. Navigate to the account entity for which you want to add this custom filtered lookup.
  5. Access the Account form.

    custom filtered lookup in CRM 2011

  6. In the form that opened, double click on the Form Properties button at the top.

  7. In the popup that opens up, add the web resource you have created in step 1.

  8. Go to the form OnLoad event, click Add, and call the formOnLoad function by passing the parent account and primary contact field names as parameters.

    This is the form OnLoad event screen shot after calling the function:

  9. Go to the OnChange event of the Parent Account field and call the setPrimaryConatactLookup function by passing the parent account and primary contact field names, true as parameters.

  10. Save the changes.
  11. Publish customizations.

    After implementing all these steps, once you click on the lookup icon of the Primary Contact field, you should see the custom filtered lookup created for the Primary Contact as shown in the screenshot below.

custom_filtered_lookup_last_image

We hope this was helpful! If you need assistance with anything related to Microsoft Dynamics CRM, we’ve got a great support team and we’re happy to help.

Happy CRM’ing!

Avatar for JoeCRM

JoeCRM

Joe CRM is a CRM superhero who runs on pure Microsoft Dynamics CRM adrenaline. As the face of PowerObjects, Joe CRM’s mission is to reveal innovative ways to use Dynamics CRM and bring the application to more businesses and organizations around the world.