Hello All,
Below is a quick code snippet that can retrieve picklist label based on value,
To know more on conditional operator with question mark, please refer
http://exptechsolutions.blogspot.com/2017/05/c-null-conditional-operator-null-check.html
Below is a quick code snippet that can retrieve picklist label based on value,
private string GetOptionsSetTextOnValue(IOrganizationService service,string entityName, string attributeName, int option)
{
RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
{
EntityLogicalName = entityName,
LogicalName = attributeName,
RetrieveAsIfPublished = true
};
RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
PicklistAttributeMetadata attributeMetadata = (PicklistAttributeMetadata)retrieveAttributeResponse?.AttributeMetadata;
if (attributeMetadata == null) return string.Empty;
var currentOption = attributeMetadata?.OptionSet?.Options?.FirstOrDefault(x => x.Value == option);
return currentOption?.Label?.UserLocalizedLabel?.Label != null ? currentOption.Label.UserLocalizedLabel.Label : string.Empty;
}
To know more on conditional operator with question mark, please refer
http://exptechsolutions.blogspot.com/2017/05/c-null-conditional-operator-null-check.html
*This post is locked for comments