Επεξεργασία

Κοινή χρήση μέσω


Customize entity attribute metadata

Use AttributeMetadata (AttributeMetadata EntityType or AttributeMetadata class) to retrieve existing attributes. The AttributeMetadata class is returned by the RetrieveAttributeRequest message. The AttributeMetadata inherits from the abstract MetadataBase (MetadataBase EntityType for Web API and MetadataBase in case of Organization Service).

Use the following Web API query to retrieve entity attributes in the context of an entity by expanding the Attributes collection-valued navigation property. More information: Querying EntityMetadata attributes

GET [Organization URI]/api/data/v9.1/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)?$select=LogicalName&$expand=Attributes($select=LogicalName;$filter=AttributeType eq Microsoft.Dynamics.CRM.AttributeTypeCode'Picklist')

Use the specific class for each attribute type with the CreateAttribute message (For Organization Service see, CreateAttributeRequest) to update attributes or create custom attributes.

Note

You can access custom attributes programmatically after you create them, but you must add them to an entity form and publish them before users can see them.

Attribute types

The following table lists each type of Attribute you can work with. Each attribute inherits from the AttributeMetadata.

Class Application Label Description
BooleanAttributeMetadata Two Option A Boolean attribute. You can specify the text for both options. When added to a form, the field properties control whether the attribute is displayed as two radio buttons, a check box, or a list.
DateTimeAttributeMetadata Date and Time A date and time attribute. You can specify the behavior to store date and time values with or without time zone information, and format to define the display format of the values. More information: Behavior and format of the datetime attribute Note: If you are using Dynamics 365 Customer Engagement (on-premises) or Dynamics CRM 2016 (on-premises), all date and time attributes now support values as early as 1/1/1753 12:00 AM.
DecimalAttributeMetadata Decimal Number A decimal attribute. You can specify the level of precision up to ten decimal places and the minimum and maximum values from -100,000,000,000 to 100,000,000,000.
DoubleAttributeMetadata Floating Point Number A double attribute. You can specify the level of precision up to five decimal places and the minimum and maximum values from -100,000,000,000 to 100,000,000,000. Note: DoubleAttributeMetadata replaces the FloatAttributeMetadata used in Dynamics CRM 4.0.
ImageAttributeMetadata Image An image attribute. Each entity can have one image attribute. Certain system entities have image attributes and new image attributes cannot be added to system entities that do not have them. You can add an image attribute to custom entities

All image attributes have the SchemaName ‘EntityImage’ and the LogicalName ‘entityimage’. Custom image attributes will not use the solution publisher customization prefix in the name. More information: Entity images.
IntegerAttributeMetadata Whole Number An integer attribute. You can specify the maximum and minimum values from -2,147,483,648 to 2,147,483,647.

This attribute can be formatted to create the following types of fields using the IntegerFormat enumeration( IntegerFormat EnumType or IntegerFormat enumeration):

- Duration: Displays a drop-down list that contains time intervals. A user can select a value from the list or type an integer value that represents the number of minutes.
- TimeZone: Displays a drop-down list that contains a list of time zones.
- Language: Displays a drop-down list that contains a list of languages that have been enabled for the organization. If no other languages have been enabled, the base language will be the only option. The value saved is the LCID value for the language.
LookupAttributeMetadata Lookup An attribute created when an entity relationship is created by using the CreateOneToMany message( For organization service see, CreateOneToManyRequest message).
MemoAttributeMetadata Multiple Lines of Text A memo attribute. Displays as a text box field in a form. The maximum length is 1048576 characters.
MoneyAttributeMetadata Currency A money attribute. You can specify the maximum and minimum values between - 922,337,203,685,477 and 922,337,203,685,477.

The level of precision can be set by using the MoneyAttributeMetadata.PrecisionSource property:

- When the precision is set to zero (0), the MoneyAttributeMetadata.Precision value is used.
- When the precision is set to one (1), the Organization.PricingDecimalPrecision value is used.
- When the precision is set to two (2), the TransactionCurrency.CurrencyPrecision value is used.
MultiSelectPicklistAttributeMetadata MultiSelect Option Set A multi-select picklist attribute. Multi-select picklist attributes were added with the Dynamics 365 Customer Engagement (on-premises) version 9. This attribute provides a set of options that are displayed in a drop-down list. More than one option can be selected. You can create the this attribute so that it can contain its own options or use a global options set.
PicklistAttributeMetadata Option Set A picklist attribute. This attribute provides a set of options that are displayed in a drop-down list. You can create the picklist attribute so that it can contain its own options or use a global options set.
StateAttributeMetadata Status The state attribute is created automatically when the entity is created. Note: The options available for this attribute are read-only.
StatusAttributeMetadata Status Reason The status attribute is created automatically when the entity is created. Each of the options must be associated with the StateAttributeMetadata attribute for the entity. Use the InsertStatusValueRequest message to update options available for this attribute. Note: Each StatusOption must reference a specific state attribute value because status values depend on a specific state value.
StringAttributeMetadata Single Line of Text See StringAttributeMetadata formats.

StringAttributeMetadata formats

String attributes can be formatted to allow links to initiate phone calls by using Lync or Skype. This change requires that a new FormatName property(For Organization Service see, FormatName) be added to StringAttributeMetadata (StringAttributeMetadata EntityType or StringAttributeMetadata class) and the deprecation of the Format property.

Using the StringFormat enumeration(StringFormat EnumType or StringFormat enumeration) to define the format for StringAttributeMetadata.Format(For Organization Service see, StringAttributeMetadata.Format) is deprecated. Instead, use the StringFormatName class to set the value of StringAttributeMetadata.FormatName.

This allows for setting the format value of PhoneNumber, which does not exist in the StringFormat enumeration.

For backwards compatibility, you can set a value to control how the attribute is formatted by using either the Format or FormatName property. Your existing code will continue to work if you only use Format, but you will not be able to format an attribute as a phone number without using FormatName. If both properties are set, the value set using FormatName is the one that will be applied.

The StringFormatName message (StringFormatName ComplexType or StringFormatName class) contains the following members; each member returns a string with the same value as the member name:

Member name and value Description
Email The form field will validate the text value as an e-mail address and create a mailto link in the field.
PhoneNumber The form field will contain a link to initiate a phone call by using Skype.
PhoneticGuide For internal use only.
Text The form will display a text box.
TextArea The form will display a text area field.
TickerSymbol The form will display a link that will open to display a quote for the stock ticker symbol.
URL The form will display a link to open the URL.
VersionNumber For internal use only.

See also

Extend the Metadata Model for Dynamics 365 Customer Engagement
Work with Attributes
Behavior and format of the datetime attribute
Entity Attribute Metadata Messages
Sample: Work with Attributes
Sample: Dump Attribute Metadata to a File
Sample: Dump Attribute Picklist Metadata to a File
Sample: Convert date and time behavior