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 }