Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

How To : Get the Label Value for an OptionSet Using RetrieveAttribute Request in Microsoft Dynamis CRM 2011

Leave a comment

The following code helps you to the get label of an option value.

Code:

private string GetCRMOptionSetLabel(IOrganizationService service, string entityname, string optionsetname, int value)
{
RetrieveAttributeRequest reqOptionSet = new RetrieveAttributeRequest();
reqOptionSet.EntityLogicalName = entityname;
reqOptionSet.LogicalName = optionsetname;
RetrieveAttributeResponse resp = (RetrieveAttributeResponse)service.Execute(reqOptionSet);
PicklistAttributeMetadata opdata = (PicklistAttributeMetadata)resp.AttributeMetadata;
var option = opdata.OptionSet.Options.FirstOrDefault(o => o.Value == value);
return option.Label.LocalizedLabels.FirstOrDefault().Label;

}

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s