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);
EntityMetadata = resp.EntityMetadata;
var attrInfo = 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