To get the value for OptionSet we can use the following function
private
string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue) {
RetrieveAttributeRequest retrieveAttributeRequest = new
RetrieveAttributeRequest {
EntityLogicalName = entityName,
LogicalName = attributeName,
RetrieveAsIfPublished = true
};
// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =(RetrieveAttributeResponse) service.Execute(retrieveAttributeRequest);
// Access the retrieved attribute.
Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata =(Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)
retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
string selectedOptionLabel = string.Empty;
foreach (OptionMetadata oMD in optionList) {
if (oMD.Value == selectedValue){selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label;
}
}
return selectedOptionLabel;
}
http://www.codeproject.com/Tips/553178/Get-the-OptionsetValue-and-OptionsetText-for-Dynam
Hope it helps !
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

Hi,
What assembly should we add?
Thank you
LikeLike
Very good.
LikeLike
great work man 🙂
LikeLike
what would be the entityname and the attributename ?
LikeLike
Thanks a lot
LikeLike
Thanks for this code. It helped a lot.
LikeLike