crm操作全局选项集

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Metadata;
    using Microsoft.Xrm.Sdk.Messages;

    /// <summary>
    /// 全局选项集
    /// </summary>
    public class OptionSetMetadataHelper
    {
        public IOrganizationService service = null;
        public Guid optionSetId = Guid.Empty;
        public int languageCode = 2052;

        /// <summary>
        /// 创建全局选项集
        /// </summary>
        public void Create()
        {
            #region OptionMetadataCollection
            OptionMetadataCollection opCollection = new OptionMetadataCollection();
            opCollection.Add(new OptionMetadata(new Label("2000年", languageCode), 2000));
            opCollection.Add(new OptionMetadata(new Label("2001年", languageCode), 2001));
            opCollection.Add(new OptionMetadata(new Label("2002年", languageCode), 2002));
            opCollection.Add(new OptionMetadata(new Label("2003年", languageCode), 2003));
            opCollection.Add(new OptionMetadata(new Label("2004年", languageCode), 2004));
            opCollection.Add(new OptionMetadata(new Label("2005年", languageCode), 2005));
            #endregion

            OptionSetMetadata optionSet = new OptionSetMetadata(opCollection);
            optionSet.Name = "new_year";
            optionSet.Description = new Label("年份", languageCode);
            optionSet.DisplayName = new Label("年份", languageCode);
            optionSet.IsGlobal = true;
            optionSet.OptionSetType = OptionSetType.Picklist;

            CreateOptionSetRequest request = new CreateOptionSetRequest();
            request.OptionSet = optionSet;
            CreateOptionSetResponse response = (CreateOptionSetResponse)service.Execute(request);
            optionSetId = response.OptionSetId;
        }

        /// <summary>
        /// 插入新全局选项集选项
        /// </summary>
        public void InsertOptionValue()
        {
            InsertOptionValueRequest request = new InsertOptionValueRequest();
            request.OptionSetName = "new_year";
            request.Label = new Label("2008年", languageCode);
            request.Value = 2008;
            InsertOptionValueResponse response = (InsertOptionValueResponse)service.Execute(request);
        }

        /// <summary>
        /// 更改选项集中选项的相对顺序
        /// </summary>
        public void OrderOption()
        {
            OrderOptionRequest request = new OrderOptionRequest();
            request.OptionSetName = "new_year";
            request.Values = new int[]{ 2005,2004,2003,2002,2001,2000 };
            OrderOptionResponse response = (OrderOptionResponse)service.Execute(request);
        }

        /// <summary>
        /// 检索所有全局选项集
        /// </summary>
        public void RetrieveAllOptionSets()
        {
            RetrieveAllOptionSetsRequest request = new RetrieveAllOptionSetsRequest();
            request.RetrieveAsIfPublished = true;
            RetrieveAllOptionSetsResponse response = (RetrieveAllOptionSetsResponse)service.Execute(request);
            OptionSetMetadataBase[] optionSetMetadata = response.OptionSetMetadata;
        }

        /// <summary>
        /// 检索全局选项集
        /// </summary>
        /// <param name="name">选项集的名称</param>
        public void RetrieveOptionSet(string name)
        {
            RetrieveOptionSetRequest request = new RetrieveOptionSetRequest();
            request.Name = name;
            request.RetrieveAsIfPublished = true;
            RetrieveOptionSetResponse response = (RetrieveOptionSetResponse)service.Execute(request);
            OptionSetMetadataBase optionSetMetadata = response.OptionSetMetadata;
        }

        /// <summary>
        /// 删除全局选项集中的项
        /// </summary>
        /// <param name="v">值</param>
        public void DeleteItem(int v)
        {
            DeleteOptionValueRequest request = new DeleteOptionValueRequest();
            request.OptionSetName = "new_year";
            request.Value = v;
            DeleteOptionValueResponse response = (DeleteOptionValueResponse)service.Execute(request);
        }

        /// <summary>
        /// 删除全局选项集
        /// </summary>
        public void Delete()
        {
            DeleteOptionSetRequest request = new DeleteOptionSetRequest();
            request.Name = "new_year";
            DeleteOptionSetResponse response = (DeleteOptionSetResponse)service.Execute(request);
        }
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值