Microsoft CRM 2011 Disable Fields From Picklist May 24, 2011
Posted by jarrettexpertcrm in Uncategorized.Tags: crm, CRM 2011, CRM 5, CRM 5.0, crm tips, Dynamics Four, Dynamics4, microsoft crm 2011 picklist, Picklist Disable
trackback

In some cases you need to disable fields based of the value of a picklist. Below is the code to achieve this.
function disableToggle()
{
var value = Xrm.Page.getAttribute(“PICKLISTFIELD”).getValue()
// First Picklist value
if (value == “100000000″)
{
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(false);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(false);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
}
// Second picklist value
else if (value == “100000001″)
{
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(false);
}
// Third picklist value
else if (value == “100000002″)
{
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(false);
}
// Fourth picklist value
else if (value == “100000003″)
{
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(true);
Xrm.Page.ui.controls.get(“FIELD”).setDisabled(false);
}
}
Enjoy!!
- JC
For more information about Dynamics Four you can contact us at http://www.dynamics4.com

Thanks.
Hi,
I am using Microsoft dynamics crm 2011. In Account form i have two fields
1)Relatioship Type and
2) Account Number
Relationship Type field is dropdown list and it contains two values
A)Customer and
B)Prospect
When i pick the Customer from Relationship Type then Account Number field is in Activate state else Account Number field is in Deactivate state.
In order to achieve this i am using your above code as reference. Please find my below code.
function disableToggle()
{
var reltype = Xrm.Page.getAttribute(“Relationship Type”).getSelectedOption().text;
// First Picklist value
if (reltype == “Customer”)
{
Xrm.Page.ui.controls.get(“Account Number”).setDisabled(false);
}
// Second picklist value
else if (reltype == “Prospect”)
{
Xrm.Page.ui.controls.get(“Account Number”).setDisabled(true);
}
}
In Account form i have copy this code and i published this. When i open the Account form it shows the below error message.
Message from Webpage:
There was an error with this field’s customizes event.
Field: customertypecode
Event:Onchange
Error:Object expected
Hi Madhava,
Try replacing your first line of code from “var reltype = Xrm.Page.getAttribute(“Relationship Type”).getSelectedOption().text;” to “var reltype = Xrm.Page.getAttribute(“PICKLISTFIELD”).getValue()”, and use the ID instead of label. I have ran into similiar issues when trying to use label.
Regards,
Jarrett