How to create Cascading Lookup in Microsoft Dynamics CRM

How to create Cascading Lookup in Microsoft Dynamics CRM

Assume there are three entities, as it is shown on Screen 1. The relations between those entities are displayed on Screens 2 and 3. Let’s create a cascading (master detail) lookup.

Microsoft Dynamics CRM

Screen 1

Microsoft Dynamics CRM image

Screen 2

Cascading Lookup in Microsoft Dynamics CRM

Screen 3

Cascading Lookup in MS Dynamics CRM

Screen 4

City lookup should be configured to show only the cities that are relevant to the selected Country lookup value in the Addresses entity. Open the city field properties dialogue in the form (See Screen 5).

To do that:

  1. Open the desired solution.
  2. Select Addresses entity Forms
  3. Open default form
  4. Select City Lookup
  5. Click on the Change Properties button

How to create Cascading Lookup in Dynamics CRM

Screen 5

As a result, the window displayed on Screen 6 appears. Dialogue menu options can be modified to display only the relevant data (See Screen 6).

Cascading Lookup

Screen 6

Now “City” displays the relevant data only. Still, there is a possibility to select a city and then a country not relevant to it. This may lead to non-synchronized data (Addresses Country and Cities Country). In this case, the incorrect data will be displayed to a user. But if the field is used in the business logic, it may cause even more troubles. To resolve this issue, validation of input data can be implemented on the SERVER side.

How to solve synchronization issue with GUI

Add JavaScript to disable and reset City Lookup when the user changes Country.

//CascadingLookUp.js

function CascadingLookUpSample_Init() {

Xrm.Page.getControl(“ut_city”).setDisabled(crmForm.all.ut_country.DataValue == null);

}

function CascadingLookUpSample_CantryOnChange() {

crmForm.all.ut_city.DataValue = null;

Xrm.Page.getControl(“ut_city”).setDisabled(crmForm.all.ut_country.DataValue == null);

}

Now bind events to the abovementioned functions. (See Screen 7, 8)

To bind CascadingLookUpSample_Init() on the form load event:

  1. Open the form
  2. Click on the Form Properties ribbon button
  3. Select Events tab in the Form Properties dialogue
  4. Add library to the libraries section, if it wasn’t done earlier
  5. Select OnLoad event from the dropdown and click the Add button placed in the Event Handlers section
  6. Set up library and handler function name in Handler Properties dialogue

Cascading Lookup in Dynamics CRM

Screen 7

To bind CascadingLookUpSample_CantryOnChange() to Country Lookup’s on change event:

  1. Select Country Lookup in the form
  2. Click on the Change property ribbon button
  3. Select Event tab in Field Properties dialogue
  4. Set up Library to CascadingLookUp and Function to CascadingLookUpSample_CantryOnChange

Cascading Lookup in Microsoft CRM

Screen 8

How to Add Custom View

 Create Cascading Lookup - CRM

Contact us

Tell your idea, request a quote or ask us a question