Nov 012011
Recently I’ve received some questions on how to change the optionset (previously called picklist) values in CRM 2011 the same way I did in my previous CRM 4 post about using the OnChange event of a yes/no field to change the values of a picklist.
This technet page shows the methods available for the different types of controls.
Here is an example of how to change the optionset based on a yes/no field:
function BuildOptionSet(picklist, valuelist)
{
picklist.clearOptions();
for(var i=0; i<valuelist.length; i++)
{
var listitem = valuelist[i];
picklist.addOption(listitem[0], listitem[1]);
}
}
var lista = new Array();
lista[0] = new Array('Alpha',0);
lista[1] = new Array('Beta',1);
var listb = new Array();
listb[0] = new Array('Charlie',2);
listb[1] = new Array('Delta',3);
var uselista = Xrm.Page.data.entity.attributes.get("YesNo").getValue();
var optionset = Xrm.Page.ui.controls.get("OptionSet");
if (uselista==true) {
BuildOptionSet(optionset, lista);
} else {
BuildOptionSet(optionset, listb);
}
You just need to change the values of lista and listb and the YesNo and OptionSet lines to reflect the fields on your form, and add it to the onchange event of the dropdown Yes/No form field.
