9.0 sdk 多选选项集

        public string OptionSetVelueC(IOrganizationService serviceAdmin, Entity entity, string str, string _entityName, int[] i = null)
        {
            if (entity.Attributes.Contains(str))
            {
                string ss = "";
                OptionSetValueCollection optionSetValues = entity.Attributes[str] as OptionSetValueCollection;
                var req = new RetrieveEntityRequest
                {
                    EntityFilters = EntityFilters.Attributes,
                    LogicalName = _entityName,
                    RetrieveAsIfPublished = true
                };
                var resp = (RetrieveEntityResponse)serviceAdmin.Execute(req);
                var attrInfo = resp.EntityMetadata.Attributes.First(a => a.LogicalName == str);
                var pick = attrInfo as MultiSelectPicklistAttributeMetadata;
                foreach (var option in pick.OptionSet.Options)
                {
                    if (null != i)
                    {
                        if (i.Contains(option.Value.Value))
                        {
                            ss += option.Label.UserLocalizedLabel.Label + ",";
                        }
                    }
                    else
                    {
                        if (optionSetValues.Select(x => x.Value).ToList().Contains(option.Value.Value))
                        {
                            ss += option.Label.UserLocalizedLabel.Label + ",";
                        }
                    }
                }
                if (!string.IsNullOrEmpty(ss))
                {
                    ss = ss.Substring(0, ss.Length - 1);
                    return ss;
                }
            }
            return "";
        }

  

原文地址:https://www.cnblogs.com/ly1998/p/12022612.html