Microsoft Dynamics CRM building developing and creating multiple Dependant pick lists / Option Sets / drop down menus

There are many different ways of how to create Dynamics CRM dependant picklist (option sets). Dependant optionsets is a common requirement where values in one option set field need to be filtered by a value chosen in another option set field. (For example: Multiple option set categories and sub categories based on value selected in the category field picklist).

Option 1:

The “official” approach to develop dependent picklists is explained in the CRM 2011 SDK here:
http://msdn.microsoft.com/en-us/library/gg594433.aspx

This article refers to the managed solution DependentOptionSetsSample_1_0_0_0_managed.zip from the CRM SDK available in this location: SDK\SampleCode\JS\FormScripts

The rest of article shows how to implement this solution.

Option 2:

In my view, the following managed solution is the easiest way as it provides a SilverLight application to create a Dependent Picklist by using a user friendly interface.

You can see the details of this managed solution in the following MSDN blog post (by Microsoft France):
http://blogs.msdn.com/b/paf/archive/2011/04/21/how-to-easily-create-dependent-picklist-in-crm-2011.aspx

There is also another post related to this solution that provides solution to some issues:

http://blogs.msdn.com/b/paf/archive/2011/09/29/dependent-picklist-recurrent-problems.aspx

Option 3:

Finally, the third way of configuring dependant option sets in Dynamics CRM is to do it via JavaScript. This can be done in various ways but below is one way of doing it (code provided by Palak Sheh):

First function : To only show options related to the selected value in another option set:

FilterOptionSet = function (OptionSetFieldName, filterOptionsText, failOnError) {

try {
   var arroptions;
   var arrfilteroptions;
   var control = Xrm.Page.ui.controls.get(OptionSetFieldName);
   if (typeof (control) == 'undefined' || control == null) {
   return !failOnError;
  }
  arrfilteroptions = filterOptionsText.split(",");
  if (control.getControlType() == 'optionset') {
  arroptions = control.getAttribute().getOptions();
  for (var i = 0; i <= arroptions.length - 1; i++) {
  var removeItem = true;
  for (var j = 0; j <= arrfilteroptions.length - 1; j++) {
  if (arrfilteroptions[j] == arroptions[i].value) {
  removeItem = false;
  break;
 }
}

if (removeItem) {
 control.removeOption(arroptions[i].value);
   }
  }
 }
}
 catch (e) {
 if (!failOnError) {
    return true;
 }
 alert('Error FilterOptionSet: ' + e.message);
 return true;
 }
};

Second Function : To refresh the optionset everytime

RefreshPicklist = function (OptionSetFieldName, failOnError) {
try {
 var arroptions;
 var arrfilteroptions;
 var control = Xrm.Page.ui.controls.get(OptionSetFieldName);
 if (typeof (control) == 'undefined' || control == null) {
 return !failOnError;
 }
if (control.getControlType() == 'optionset') {
   arroptions = control.getAttribute().getOptions();
   control.clearOptions();
   for (var i = 0; i <= arroptions.length - 1; i++) {
   control.addOption(arroptions[i]);
   }
  }
  }
  catch (e) {
   if (!failOnError) {
   return true;
  }
  alert('Error RefreshPicklist: ' + e.message);
  return true;
 }
};

 

Thanks

M

One Reply to “Microsoft Dynamics CRM building developing and creating multiple Dependant pick lists / Option Sets / drop down menus”

Please comment or leave feedback