इसके माध्यम से साझा किया गया


Write scripts for composite attributes

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

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 Dynamics 365 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 getValue, you can’t use 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 Dynamics 365 for tablets

Microsoft Dynamics 365 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 Dynamics 365 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.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 Dynamics 365 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.getClient as shown in the following function that will display the formatted address using Xrm.Utility.alertDialog in either the main web application or the Dynamics 365 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 365 forms
Use form and field events
Use the Xrm.Page object model
Write and debug scripts for Dynamics 365 for phones and tablets
Use execution context and the form event pipeline
Use IFRAME and web resource controls on a form
Form scripting quick reference
Client-side programming reference
Xrm.Page.data.entity attribute (client-side reference)

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright