CreateAttributeRequest 클래스
Contains the data that is needed to create a new attribute, and optionally, to add it to a specified unmanaged solution.
네임스페이스: Microsoft.Xrm.Sdk.Messages
어셈블리: Microsoft.Xrm.Sdk(Microsoft.Xrm.Sdk.dll에 있음)
구문
‘선언
<DataContractAttribute(Namespace:="https://schemas.microsoft.com/xrm/2011/Contracts")> _
Public NotInheritable Class CreateAttributeRequest
Inherits OrganizationRequest
[DataContractAttribute(Namespace="https://schemas.microsoft.com/xrm/2011/Contracts")]
public sealed class CreateAttributeRequest : OrganizationRequest
예제
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<AttributeMetadata>();
// Create a boolean attribute
BooleanAttributeMetadata boolAttribute = new BooleanAttributeMetadata
{
// Set base properties
SchemaName = "new_boolean",
DisplayName = new Label("Sample Boolean", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Boolean Attribute", _languageCode),
// Set extended properties
OptionSet = new BooleanOptionSetMetadata(
new OptionMetadata(new Label("True", _languageCode), 1),
new OptionMetadata(new Label("False", _languageCode), 0)
)
};
// Add to list
addedAttributes.Add(boolAttribute);
// Create a date time attribute
DateTimeAttributeMetadata dtAttribute = new DateTimeAttributeMetadata
{
// Set base properties
SchemaName = "new_datetime",
DisplayName = new Label("Sample DateTime", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("DateTime Attribute", _languageCode),
// Set extended properties
Format = DateTimeFormat.DateOnly,
ImeMode = ImeMode.Disabled
};
// Add to list
addedAttributes.Add(dtAttribute);
// Create a decimal attribute
DecimalAttributeMetadata decimalAttribute = new DecimalAttributeMetadata
{
// Set base properties
SchemaName = "new_decimal",
DisplayName = new Label("Sample Decimal", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Decimal Attribute", _languageCode),
// Set extended properties
MaxValue = 100,
MinValue = 0,
Precision = 1
};
// Add to list
addedAttributes.Add(decimalAttribute);
// Create a integer attribute
IntegerAttributeMetadata integerAttribute = new IntegerAttributeMetadata
{
// Set base properties
SchemaName = "new_integer",
DisplayName = new Label("Sample Integer", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Integer Attribute", _languageCode),
// Set extended properties
Format = IntegerFormat.None,
MaxValue = 100,
MinValue = 0
};
// Add to list
addedAttributes.Add(integerAttribute);
// Create a memo attribute
MemoAttributeMetadata memoAttribute = new MemoAttributeMetadata
{
// Set base properties
SchemaName = "new_memo",
DisplayName = new Label("Sample Memo", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Memo Attribute", _languageCode),
// Set extended properties
Format = StringFormat.TextArea,
ImeMode = ImeMode.Disabled,
MaxLength = 500
};
// Add to list
addedAttributes.Add(memoAttribute);
// Create a money attribute
MoneyAttributeMetadata moneyAttribute = new MoneyAttributeMetadata
{
// Set base properties
SchemaName = "new_money",
DisplayName = new Label("Money Picklist", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Money Attribue", _languageCode),
// Set extended properties
MaxValue = 1000.00,
MinValue = 0.00,
Precision = 1,
PrecisionSource = 1,
ImeMode = ImeMode.Disabled
};
// Add to list
addedAttributes.Add(moneyAttribute);
// Create a picklist attribute
PicklistAttributeMetadata pickListAttribute =
new PicklistAttributeMetadata
{
// Set base properties
SchemaName = "new_picklist",
DisplayName = new Label("Sample Picklist", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Picklist Attribute", _languageCode),
// Set extended properties
// Build local picklist options
OptionSet = new OptionSetMetadata
{
IsGlobal = false,
OptionSetType = OptionSetType.Picklist,
Options =
{
new OptionMetadata(
new Label("Created", _languageCode), null),
new OptionMetadata(
new Label("Updated", _languageCode), null),
new OptionMetadata(
new Label("Deleted", _languageCode), null)
}
}
};
// Add to list
addedAttributes.Add(pickListAttribute);
// Create a string attribute
StringAttributeMetadata stringAttribute = new StringAttributeMetadata
{
// Set base properties
SchemaName = "new_string",
DisplayName = new Label("Sample String", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("String Attribute", _languageCode),
// Set extended properties
MaxLength = 100
};
// Add to list
addedAttributes.Add(stringAttribute);
// 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.
foreach (AttributeMetadata anAttribute in addedAttributes)
{
// Create the request.
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
{
EntityName = Contact.EntityLogicalName,
Attribute = anAttribute
};
// Execute the request.
_serviceProxy.Execute(createAttributeRequest);
Console.WriteLine("Created the attribute {0}.", anAttribute.SchemaName);
}
설명
Message Availability
이 메시지가 작동하려면 호출자가 서버에 연결되어야 합니다.
Usage
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 Privileges.
Notes for Callers
This message cannot be used to create a LookupAttributeMetadata attribute. Use the CreateOneToManyRequest message to create an entity relationship that includes the lookup attribute.
Supported Entities
You can only add attributes to customizable entities where the managed property CanCreateAttributes is true.
상속 계층
System.Object
Microsoft.Xrm.Sdk.OrganizationRequest
Microsoft.Xrm.Sdk.Messages.CreateAttributeRequest
스레드 보안
이 형식의 공용 정적(Visual Basic에서는 Shared) 구성원은 스레드로부터 안전합니다. 인스턴스 구성원은 스레드로부터 안전하지 않을 수 있습니다.
플랫폼
Development Platforms
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Target Platforms
Windows Server 2008,Windows Server 2012,Windows 7
Change History
참고 항목
참조
CreateAttributeRequest 구성원
Microsoft.Xrm.Sdk.Messages 네임스페이스
CreateAttributeResponse
기타 리소스
Customize Entity Attribute Metadata
Entity Attribute Metadata Messages
Sample: Create and Update Entity Metadata
CreateAttribute Privileges
Introduction to Solutions
Send comments about this topic to Microsoft.
© 2015 Microsoft. All rights reserved.