Posted in CRM, JavaScripts

Dependent Optionset/ Pick List

Dependent Optionset/ Pick List

In a recent scenario, I was asked to create a dependent Pick-list/ Option set list where the options of Second Pick-list are dependent on the Value of the First one. By default there is no such option in Dynamics CRM but I came up with a solution from SDK.

Optionsets are-

  1. category- Gold, Silver, Diamond

2.Subcategory-

gold1,gold2,gold3,gold4,silver1,silver2,silver3,silver4,diamond1,diamond2,diamod4

var gold=1;
var silver =2;
var diamond =3;
var subcategory ="new_subcategory",
 subcategorygold=[1,2,3,4],
 subcategorysilver=[5,6,7,8],
 subcategorydiamond=[9,10,11,12];


function optionset()
{
 debugger;
 var categoryattribute = Xrm.Page.getAttribute("new_category").getValue();
 var subcategoryattr= Xrm.Page.getAttribute(subcategory);
 var subcategorycontrol= Xrm.Page.getControl(subcategory);
 switch(categoryattribute)
 {
 case gold :
 addoptionset(subcategoryattr,subcategorygold,subcategorycontrol)
 break;
 case silver:
 addoptionset(subcategoryattr,subcategorysilver,subcategorycontrol)
 break;
 case diamond:
 addoptionset(subcategoryattr,subcategorydiamond,subcategorycontrol)
 break;
 }
 
}

function addoptionset(attribute,subcat,control)
{
 control.clearOptions();
 subcat.forEach(function(currentoption, Index)
 {
 var option= attribute.getOption(currentoption);
 control.addOption(option,Index);
 });
 
}
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