Accessing Composite Controls Programmatically using Script

By | October 10, 2014

You might have disabled normal controls programmatically many times but while disabling Composite Controls programmatically we get stuck. We don’t know how to access the control and going through the conventional method doesn’t yield us the expected result.

In that case, what should we do? How to achieve the expected result? Like this, we face many questions but we don’t get proper answer for any of these questions. What if we say the answer to these all questions is indeed very simple. Yes, the answer is very simple.

To be truthful, even we were stuck on this, we had a requirement in which we were supposed to conditionally disable the Composite Controls as per the client from which it is accessed i.e., Web Application or Mobile. At that time even we weren’t quite sure how to do it. But after an extensive research we found a very simple solution to our problem.

Below piece of code will solve the mystery surrounded on how to access the Composite Controls:

Syntax:

(Composite control name)_compositionLinkControl_(Attribute Name)

For E.g.:

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

The above piece of code is to disable the City attribute of the address1 composite control.

This way you can access all the composite fields in the CRM.

Composite attributes

The following table lists the composite attributes:

Entity Display Name Logical name
Contact
Full Name
fullname
Address 1 address1_composite
Address 2 address2_composite
Lead Full Name Fullname
Address 1 address1_composite
Address 2 address2_composite
User
Full Name
Fullname
Address address1_composite
Other Address address2_composite
Account Address 1 address1_composite
Address 2 address2_composite
Quote
Bill To Address
billto_composite
Ship To Address shipto_composite
Order
Bill To Address
billto_composite
Ship To Address
shipto_composite
Invoice
Bill To Address
billto_composite
Ship To Address shipto_composite

Note:

  • This way you can access the Composite Controls and set values on Tablet as well. The above technique is compatible for Tablets.
  • You can access Composite Controls using the above technique and use all the available methods like setDisabled, setVisible, setLabel, etc.
  • If you want to perform any action on Composite Control as a whole then you can access it the conventional way, Xrm.Page.getControl(“address1_composite”).