using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
/// <summary>
/// 创建DateTime类型的字段
/// </summary>
public class CreateDateTimeAttribute
{
private string entityName = "new_class";
public void Create(IOrganizationService service)
{
CreateAttributeRequest request = new CreateAttributeRequest();
//关联的实体名称
request.EntityName = entityName;
DateTimeAttributeMetadata dateAttr = new DateTimeAttributeMetadata();
//字段名称
dateAttr.LogicalName = "new_datetimevalue";
//架构名称
dateAttr.SchemaName = "new_datetimevalue";
//显示中文名称
dateAttr.DisplayName = new Label("DateTime字段", 2052);
//描述
dateAttr.Description = new Label("DateTime字段", 2052);
//需求级别
dateAttr.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);
//字段安全性
dateAttr.IsSecured = false;
//审核
dateAttr.IsAuditEnabled = new BooleanManagedProperty(false);
//IME模式
dateAttr.ImeMode = ImeMode.Disabled;
//日期格式
//如果是2014-06-02 12:20:30 : DateTimeFormat.DateAndTime
dateAttr.Format = DateTimeFormat.DateAndTime;
//如果是2014-06-02 : DateTimeFormat.DateOnly
//dateAttr.Format = DateTimeFormat.DateOnly;
request.Attribute = dateAttr;
service.Execute(request);
}
}
crm2011创建DateTime类型的字段,布布扣,bubuko.com