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 ""; }