CRM Blog

Adding A Filtered Lookup In CRM

by Danny Varghese 02.03.09

Another common question I see in blogs from users are is there a way to add filtered lookups?  That is only allow users to "lookup" certain records that related to that particular one.  Here's a real life example:

 

Say you have an account that has a 1:N parental relationship with entity A.  Now let's say there's another entity B that has N:1 referential relationships with both account, and entity A.  There is a way on entity B so that after you select, on the lookup, a record of the account you want to relate to it, to filter the second lookup of entity A to only those related to the account you just selected.  i.e.

 

Parental Relationship

Account --> Entity A

 

Referential Relationship

Entity B -- Account

Entity B -- Entity A

 

With simple JavaScript, when a user selects the lookup value for the account, the lookup for Entity A can be filtered to point to only those entity A's that are related to the account you just chose.  Here's the code to place on the form of Entity B:

 

crmForm.all.<lookup field for entity A>.additionalparams = 'search=' + encodeURIComponent(crmForm.all.<lookup field for account>.DataValue[0].name);

 

That's it!  Simple, yet effective.

Filed under:

Comments

# Filter Lookup Records returned by Add Existing Button | keyongtech said on February 16, 2009 04:09 PM:

Pingback from  Filter Lookup Records returned by Add Existing Button | keyongtech

# pmdci said on February 18, 2009 12:49 AM:

Nice one. I would if it would work in a similar scenario?

Account has two new entities with N:1 relationship:

1. Country (has just one attribute: Country Name)

2. Region (one attribute: Region Name, plus a N:1 relationship with Country)

Now back in the Account form, when selecting a region, its lookup form should ONLY display the regions related to the selected Country.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Security Check
Please answer the simple math problem below.

(required)