This article was written for CRM 4. If you are interested in seeing how this would be done in CRM 2011, please click here.
Recently on the Microsoft forums someone asked how to change the values of a picklist based on the yes no value of a boolean field. Just add this script to the OnChange event of the yes/no field.
This technet page shows some of the functions on different form fields.
Here is an example of how to change the picklist based on a yes/no field:
function CreatePicklistValue(Name,Value)
{
var retval = new Array();
retval[0] = Name;
retval[1] = Value;
return retval;
}
function BuildPickList(picklist, valuelist)
{
var options = picklist.Options;
for(var i=0; i<options.length; i++)
{
var option = options[i];
picklist.DeleteOption(option.DataValue);
}
for(var j=0; j<valuelist.length; j++)
{
var listitem = valuelist[j];
picklist.AddOption(listitem[0], listitem[1]);
}
}
var lista = new Array();
lista[0] = CreatePicklistValue('Alpha',0);
lista[1] = CreatePicklistValue('Beta',1);
var listb = new Array();
listb[0] = CreatePicklistValue('Charlie',2);
listb[1] = CreatePicklistValue('Delta',3);
var uselista = crmForm.all.YesNo.DataValue;
var picklist = crmForm.all.Picklist;
if (uselista==true) {
BuildPickList(picklist, lista);
} else {
BuildPickList(picklist, listb);
}
You just need to change the values of lista and listb, and the crmForm.all.YesNo and crmForm.all.Picklist.


I have
var oRealatedPicklist = Xrm.Page.getAttribute(“new_soustype”);
but var oRealatedPicklist.AddOption does not exist.. nor DeleteOption
Why ?
Thanks
It looks like you are using CRM 2011. I posted an updated CRM 2011 version here.