您的位置:首页 > 其它

crm2011创建Boolean类型字段

2014-06-09 09:46 399 查看
using System;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Messages;

using Microsoft.Xrm.Sdk.Metadata;

/// <summary>

/// Boolean

/// </summary>

public class CreateBooleanAttributeHelper

{

private string entityName = "new_class";

public void Create(IOrganizationService service)

{

CreateAttributeRequest request = new CreateAttributeRequest();

//关联的实体名称

request.EntityName = entityName;

BooleanAttributeMetadata boolAttribute = new BooleanAttributeMetadata();

//字段名称

boolAttribute.LogicalName = "new_boolvalue";

//架构名称

boolAttribute.SchemaName = "new_boolvalue";

//显示中文名称

boolAttribute.DisplayName = new Label("Boolean字段", 2052);

//描述

boolAttribute.Description = new Label("Boolean字段", 2052);

//需求级别

boolAttribute.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);

//字段安全性

boolAttribute.IsSecured = false;

//审核

boolAttribute.IsAuditEnabled = new BooleanManagedProperty(false);

//选项

BooleanOptionSetMetadata optionSet = new BooleanOptionSetMetadata();

optionSet.FalseOption = new OptionMetadata(new Label("False", 2052), 0);

optionSet.TrueOption = new OptionMetadata(new Label("True", 2052), 1);

boolAttribute.OptionSet = optionSet;

//默认值

boolAttribute.DefaultValue = false;

request.Attribute = boolAttribute;

service.Execute(request);

}

}

结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: