Disable a composite control’s individual element in Dynamics CRM

Just the other day we had a requirement from the client where the in the contact form, if the user enters the zip code, state and the City would be populated automatically based on the zip code entered and the user should not be able to edit the state and the City fields.

Simple isn’t it. City schema name is address1_city and for state it is address1_stateorprovince. So my colleague was trying the following statements.

Xrm.Page.getControl(“address1_city”).setDisabled(true);

Xrm.Page.getControl(“address1_stateorprovince”).setDisabled(true);

And sadly enough it did not work. My colleague was getting an error.

The question is WHY? The reason is address1_city and address1_stateorprovince are individual elements of the composite control address1_composite. To fetch the individual control of the composite control, the format is <composite control name>_compositionLinkControl_<individual control name>. So to access the city control the code to do that would be as specified below.

Xrm.Page.getControl(“address1_composite_compositionLinkControl_address1_city”).setDisabled(true);

And you are done!

 

Please note: This would not work in tablet client since in tablet client, all the composite controls fields are rendered individually on the form. Hence to get access to the control you just have to specify. its schema name.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s