CreateAttributeRequest Class


Updated: November 29, 2016

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

Contains the data that is needed to create a new attribute, and optionally, to add it to a specified unmanaged solution.

Namespace:   Microsoft.Xrm.Sdk.Messages
Assembly:  Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)


<DataContractAttribute(Namespace := "")>
Public NotInheritable Class CreateAttributeRequest
	Inherits OrganizationRequest


Initializes a new instance of the CreateAttributeRequest class.


Gets or sets the definition of the attribute type that you want to create. Required.


Gets or sets the name of the entity for which you want to create an attribute. Required.


Gets or sets the structure that contains extra data. Optional.(Inherited from OrganizationRequest.)


Gets or sets the indexer for the Parameters collection.(Inherited from OrganizationRequest.)


Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)


Gets or sets the ID of an asynchronous operation (system job). Optional. (Inherited from OrganizationRequest.)


Gets or sets the name of the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)


Gets or sets the name of the unmanaged solution to which you want to add this attribute. Optional.


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)

Message Availability

For this message to work, the caller must be connected to the server.


Pass an instance of this class to the Execute method, which returns an instance of the CreateAttributeResponse class.

Privileges and Access Rights

To perform this action, the caller must have the required privileges, as listed in CreateAttribute message privileges.

Notes for Callers

This message cannot be used to create a LookupAttributeMetadata attribute or a customer lookup attribute. Use the CreateOneToManyRequest message to create a lookup attribute and the CreateCustomerRelationshipsRequest message to create a customer lookup attribute.

Supported Entities

You can only add attributes to customizable entities where the managed property CanCreateAttributes is true.

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. For the complete sample, see the link later in this topic.

This code defines the AttributeMetadata for a number of different types of attributes and adds them to a List<AttributeMetadata>. At the end of the code, the CreateAttributeRequest class prepares the request, and the attribute is created by using the Execute method.

This code sample assumes that the current customization prefix is ‘new’ because that is the default customization prefix for the organization solution publisher. You should use the customization prefix for the solution publisher that makes sense for the solution context in which you work.

' Create storage for new attributes being created
addedAttributes = New List(Of AttributeMetadata)()

' Create a boolean attribute
Dim boolAttribute As BooleanAttributeMetadata = New BooleanAttributeMetadata With {
 .SchemaName = "new_boolean",
 .DisplayName = New Label("Sample Boolean", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("Boolean Attribute", _languageCode),
 .OptionSet = New BooleanOptionSetMetadata(
  New OptionMetadata(
   New Label("True", _languageCode), 1),
   New OptionMetadata(
   New Label("False", _languageCode), 0)
' Set base properties
' Set extended properties

' Add to list

' Create a date time attribute
Dim dtAttribute As DateTimeAttributeMetadata = New DateTimeAttributeMetadata With {
 .SchemaName = "new_datetime",
 .DisplayName = New Label("Sample DateTime", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("DateTime Attribute", _languageCode),
 .Format = DateTimeFormat.DateOnly,
 .ImeMode = ImeMode.Disabled}
' Set base properties
' Set extended properties

' Add to list

' Create a decimal attribute    
Dim decimalAttribute As DecimalAttributeMetadata = New DecimalAttributeMetadata With {
 .SchemaName = "new_decimal",
 .DisplayName = New Label("Sample Decimal", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("Decimal Attribute", _languageCode),
 .MaxValue = 100,
 .MinValue = 0,
 .Precision = 1}
' Set base properties
' Set extended properties

' Add to list

' Create a integer attribute    
Dim integerAttribute As IntegerAttributeMetadata = New IntegerAttributeMetadata With {
 .SchemaName = "new_integer",
 .DisplayName = New Label("Sample Integer", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("Integer Attribute", _languageCode),
 .Format = IntegerFormat.None,
 .MaxValue = 100,
 .MinValue = 0}
' Set base properties
' Set extended properties

' Add to list

' Create a memo attribute 
Dim memoAttribute As MemoAttributeMetadata = New MemoAttributeMetadata With {
 .SchemaName = "new_memo",
 .DisplayName = New Label("Sample Memo", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("Memo Attribute", _languageCode),
 .Format = StringFormat.TextArea,
 .ImeMode = ImeMode.Disabled,
 .MaxLength = 500}
' Set base properties
' Set extended properties

' Add to list

' Create a money attribute    
Dim moneyAttribute As MoneyAttributeMetadata = New MoneyAttributeMetadata With {
 .SchemaName = "new_money",
 .DisplayName = New Label("Money Picklist", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("Money Attribue", _languageCode),
 .MaxValue = 1000.0,
 .MinValue = 0.0,
 .Precision = 1,
 .PrecisionSource = 1,
 .ImeMode = ImeMode.Disabled}
' Set base properties
' Set extended properties

' Add to list

' Create a picklist attribute    
Dim pickListAttribute As PicklistAttributeMetadata = New PicklistAttributeMetadata With {
 .SchemaName = "new_picklist",
 .DisplayName = New Label("Sample Picklist", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("Picklist Attribute", _languageCode)}
Dim pickListOptionSetMetadata As OptionSetMetadata = New OptionSetMetadata() With {
 .IsGlobal = False,
 .OptionSetType = OptionSetType.Picklist}
pickListOptionSetMetadata.Options.Add(New OptionMetadata(New Label("Created", _languageCode), Nothing))
pickListOptionSetMetadata.Options.Add(New OptionMetadata(New Label("Updated", _languageCode), Nothing))
pickListOptionSetMetadata.Options.Add(New OptionMetadata(New Label("Deleted", _languageCode), Nothing))
pickListAttribute.OptionSet = pickListOptionSetMetadata
' Set base properties
' Set extended properties
' Build local picklist options

' Add to list

' Create a string attribute
Dim stringAttribute As StringAttributeMetadata = New StringAttributeMetadata With {
 .SchemaName = "new_string",
 .DisplayName = New Label("Sample String", _languageCode),
 .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 .Description = New Label("String Attribute", _languageCode),
 .MaxLength = 100}
' Set base properties
' Set extended properties

' Add to list

' NOTE: LookupAttributeMetadata cannot be created outside the context of a relationship.
' Refer to the WorkWithRelationships.cs reference SDK sample for an example of this attribute type.

' NOTE: StateAttributeMetadata and StatusAttributeMetadata cannot be created via the SDK.

For Each anAttribute As AttributeMetadata In addedAttributes
 ' Create the request.
 Dim createAttributeRequest As CreateAttributeRequest = New CreateAttributeRequest With {
  .EntityName = Contact.EntityLogicalName,
  .Attribute = anAttribute}

 ' Execute the request.

 Console.WriteLine("Created the attribute {0}.", anAttribute.SchemaName)
Next anAttribute

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions