• Dynamics 365单项选项集&多项选项集


     1         ///多选选项集&OptionSetValueCollection
     2         ///处理只需要使用foreach循环遍历OptionSetValueCollection即可
     3         /// <summary>
     4         /// 获取选项集的Label
     5         /// </summary>
     6         /// <param name="entityName"></param>
     7         /// <param name="fieldName"></param>
     8         /// <param name="optionSetValue"></param>
     9         /// <returns></returns>
    10         public static string GetOptionSetValueLabel(string entityName, string fieldName, int optionSetValue, IOrganizationService serviceAdmin)
    11         {
    12             var attReq = new RetrieveAttributeRequest();
    13             attReq.EntityLogicalName = entityName;
    14             attReq.LogicalName = fieldName;
    15             attReq.RetrieveAsIfPublished = true;
    16 
    17             var attResponse = (RetrieveAttributeResponse)serviceAdmin.Execute(attReq);
    18             var attMetadata = (EnumAttributeMetadata)attResponse.AttributeMetadata;
    19 
    20             return attMetadata.OptionSet.Options.Where(x => x.Value == optionSetValue).FirstOrDefault().Label.UserLocalizedLabel.Label;
    21         }
    22 
    23         /// <summary>
    24         /// 获取选项集的value
    25         /// </summary>
    26         /// <param name="entityName"></param>
    27         /// <param name="fieldName"></param>
    28         /// <param name="optionSetValue"></param>
    29         /// <returns></returns>
    30 
    31         public static int GetOptionSetValueLabel(string entityName, string fieldName, string optionSetLabel, IOrganizationService serviceAdmin)
    32         {
    33             
    34             var attReq = new RetrieveAttributeRequest();
    35             attReq.EntityLogicalName = entityName;
    36             attReq.LogicalName = fieldName;
    37             attReq.RetrieveAsIfPublished = true;
    38 
    39             var attResponse = (RetrieveAttributeResponse)serviceAdmin.Execute(attReq);
    40             var attMetadata = (EnumAttributeMetadata)attResponse.AttributeMetadata;
    41 
    42             return attMetadata.OptionSet.Options.Where(x => x.Label.UserLocalizedLabel.Label.Equals(optionSetLabel)).FirstOrDefault().Value.Value;
    43         }
  • 相关阅读:
    Databases Questions & Answers
    SQL语句
    常见的数据库基础面试题大全
    关于GET POST
    经常遇到的浏览器兼容性问题
    关于JavaScript中apply与call的用法意义及区别(转)
    js闭包的用途
    深入理解js闭包
    undefined与null的区别
    HeapSort快速排序
  • 原文地址:https://www.cnblogs.com/ly1998/p/15500270.html
Copyright © 2020-2023  润新知