Udostępnij za pośrednictwem


Write scripts for composite attributes

 

Applies To: Dynamics CRM 2015

Some fields added to a form can represent multiple items of data. These composite attributes behave differently from other attributes when displayed in the web application and you must write scripts differently to use them properly.

In This Topic

Composite attributes

Composite attributes in the web application

Composite attributes in CRM for tablets

Mitigate the differences

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

Composite attributes in the web application

When fields for composite attributes are added to a main form, the web application will show just the composite attribute. When someone edits the field, a flyout appears showing the individual attributes that comprise the composite attribute. Although not explicitly added to the form in the form editor, each of the attributes that are part of the attribute are available to the form. Although you can read the value of the composite value using 6881e99b-45e4-4552-8355-2eef296f2cd8#BKMK_getValue, you can’t use 6881e99b-45e4-4552-8355-2eef296f2cd8#BKMK_setValue to change the value of the composite attribute directly; you must set one or more of the attributes referenced by the composite attribute.

You can access the individual constituent controls displayed in the flyout by name. These controls use the following naming convention: <composite control name>_compositionLinkControl_<constituent attribute name>. To access just the address_line1 control in the address1_composite control you would use: Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_line1").

Composite attributes in CRM for tablets

Microsoft Dynamics CRM for tablets uses the same form definitions used for the entities that have composite attributes but it interprets them differently. If a composite attribute is found in the form definition, it will show all the attributes that are part of the composite attribute in that section of the form. There is no need for a flyout because all the fields are visible. You can write scripts for the form accessing each of the individual attributes just as if they had been individually added to the form.

However, the actual composite control will not be present in the CRM for tablets page.

Mitigate the differences

If you want to access the fullname field for the Contact, Lead, or User entities, using the **Xrm.Page.data.entity.**fbaf2e7a-db2f-448f-bd24-6b3ca1ccb28e#BKMK_getPrimaryAttributeValue method is an easy way to get the value for this attribute without referencing it directly. This method works for both the web application and CRM for tablets.

If you have code that needs to read the value of one of the address composite attributes, to work with both clients, you need to separate the code using **Xrm.Page.context.client.**d7d0b052-abca-4f81-9b86-0b9dc5e62a66#BKMK_getclient as shown in the following function that will display the formatted address using **Xrm.Utility.**72a66f93-92df-42b9-a8fd-b6125c7fe83b#BKMK_alertDialog in either the main web application or the CRM for tablets version of the same form.

function showAddressDialog() {
 var address1_compositeValue;
 if (Xrm.Page.context.client.getClient() != "Mobile") {
  address1_compositeValue = Xrm.Page.getAttribute("address1_composite").getValue();
 }
 else {
  var address1_line1 = Xrm.Page.getAttribute("address1_line1").getValue();
  var address1_line2 = Xrm.Page.getAttribute("address1_line2").getValue();
  var address1_line3 = Xrm.Page.getAttribute("address1_line3").getValue();
  var address1_city = Xrm.Page.getAttribute("address1_city").getValue();
  var address1_stateorprovince = Xrm.Page.getAttribute("address1_stateorprovince").getValue();
  var address1_postalcode = Xrm.Page.getAttribute("address1_postalcode").getValue();
  var address1_country = Xrm.Page.getAttribute("address1_country").getValue();

  // Achieve equivalent formatting
  //address1_line1
  //address1_line2
  //address1_line3
  //address1_city, address1_stateorprovince address1_postalcode
  //address1_country

  var addressText = "";
  if (address1_line1 != null) {
   addressText += address1_line1 + "\n";
  }
  if (address1_line2 != null) {
   addressText += address1_line2 + "\n";
  }
  if (address1_line3 != null) {
   addressText += address1_line3 + "\n";
  }
  if (address1_city != null) {
   addressText += address1_city + ", ";
  }
  if (address1_stateorprovince != null) {
   addressText += address1_stateorprovince + " ";
  }
  if (address1_postalcode != null) {
   addressText += address1_postalcode + "\n";
  }
  addressText += address1_country;

  address1_compositeValue = addressText;
 }
 Xrm.Utility.alertDialog(address1_compositeValue);
}

See Also

Write code for Microsoft Dynamics CRM forms
Use form and field events
Use the Xrm.Page object model
Write and debug scripts for CRM for tablets
Use execution context and the form event pipeline
Use an IFRAME and web resource controls on a form
Form scripting quick reference
Client-side programming reference
Xrm.Page.data.entity attribute (client-side reference)

© 2016 Microsoft. All rights reserved. Copyright