jump to navigation

Microsoft CRM 2011 Disable Fields From Picklist May 24, 2011

Posted by jarrettexpertcrm in Uncategorized.
Tags: , , , , , , , ,
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

About these ads

Comments»

1. Dharmendra - June 2, 2011

Thanks.

2. Madhava Ganji - December 7, 2011

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

jarrettexpertcrm - December 20, 2011

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


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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: