Tuesday, March 23, 2010

Filtering Lookups in CRM 4

Lets get straight to the solution. Suppose you want to filter the Primary Contact lookup on the Account entity to show only contacts that belong to the data in the Parent Account field. 

Below is a simple JavaScript code to achieve that.

  • On the forms OnLoad event write the following code.
/* Form.onLoad() */
FilterLookup = function(source, target)
if (IsNull(source) || IsNull(target)) { return; }
var name = IsNull(source.DataValue) ? '' : source.DataValue[0].name;
target.additionalparams = 'search=' + name;

  • On the OnChange event of the Parent Account lookup mention the below code.
/* onChange() */
FilterLookup(crmForm.all.parentaccountid, crmForm.all.primarycontactid);

Note : Before you can see the code working, check the Parent Customer checkbox in the Contact Lookup View. Steps ->
  • Settings > Customization > Customize Entites > Contact > Forms & Views > Contacts Lookup View
  • Click on Add Find Columns on the right
  • Tick Parent Customer
  • Click OK and Publish
After performing the above mentioned, I select "A Bike Store" as the Parent Account and click on the Primary Contact Lookup.

The Contact lookup opens(as shown in the figure below) and you can see "A Bike Store" in the search box & CRM is only returned those Contact records whose Parent Customer is "A Bike Store."

1 comment:

  1. Please Contact me as we are searching for multiple language support for CRM and Sharepoint 2010 peterspev at gmail