CRM 2011 – Implementing Dependent Lookups

Posted: May 1, 2011 in Technical
Tags: ,

In one of my previous posts, I have shown how we can implement dependent lookups in CRM 4. Fortunately, CRM 2011 has improved in this area and now we can implement this functionality with minimum effort. For the demo purpose I will use the same scenario which I used for CRM 4. If you have not read my earlier post, I suggest to go and read it so that you are aware of the scenario. In fact, you want be able to understand this post as I am basing this post on that.

As usual, lets consider the two lookup fields, Expense Category and Expense Type where expense type is depending on expense category.

exCats   exTypes

Figure 1: Expense categories & types

As usual, we will add these two as lookup fields on another entity (e.g. Expense Claim).

image2

Figure 2: Category and type are added to a form as lookup

Record Filtering

CRM 2011 allows you to filter a given set of records based on relations. For instance, in this example, the expense type and expense category are related, in which for each expense type we have a related expense category. So lets see how we can configure CRM 2011 to only show the related expense types based on some selected expense category.

In order to configure record filtering, you have to customize the containing entity form. In this example, it is the Expense Claim entity form. Once the entity form is open, select the “expense type” filed and open its properties (e.g. by double-clicking). Go to the Related Record Filtering section on Display tab. Here, you can enable the filtering by selecting Only show records where: and specifying the criteria bellow.

image

Figure 3: Enable record filtering for Expense Types lookup field.

Save and publish all customizations. Now you can check the filtering by visiting a record of the containing entity (Expense Claim). Now you will see that the types are filtered correctly based on selected category, but there is a small issue! You will see that in case we change the category again, the selected type remains intact! i.e. consider the following scenario; User selects a category and then go and select a type. This will be ok as the types shown are related to the category, but what happen if the user go and change the category again? Unfortunately, CRM 2011 doesn’t handle this scenario. How ever, we can address that as follows;

Forcing Lookup Dependencies

The easiest way we can maintain the dependencies is by clearing the dependent lookup when ever we change the value of the primary lookup. For instance, in this example, we need to clear the value of expense type when ever we change the value of expense category.

First, you need to define a JScript function to clear the value of a field. For this we will define a new web resource of type JScript and use the following JScript code.

imageFigure 4: JScript to clear the value of a field

Now, we will customize the containing form (Expense Claim) and call this function during the OnChange event of the primary lookup value (Expense Category).

image image

Figure 5: Clear Expense Type when the Expense Category is changed

Save and publish all customizations and verify the results.

Advertisements

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