Get value for OptionSet in CRM 2011

To get the value for OptionSet we can use the following function

string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)

RetrieveAttributeRequest retrieveAttributeRequest = new

EntityLogicalName = entityName,

LogicalName = attributeName,

RetrieveAsIfPublished = true

// Execute the request.

RetrieveAttributeResponse retrieveAttributeResponse =(RetrieveAttributeResponse)
// 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 =
string selectedOptionLabel = string.Empty;

foreach (OptionMetadata oMD in optionList)
if (oMD.Value == selectedValue)
{selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label;


return selectedOptionLabel;



Hope it helps !

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

6 thoughts on “Get value for OptionSet in CRM 2011”

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.