web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Using RetrieveAttribute Request in CRM 2011 To Get the Label Value for an OptionSet

Jamie Miley Profile Picture Jamie Miley 2,060
Here is a quick way to get a label for an OptionSet value in Microsoft Dynamics CRM 2011 using RetrieveAttributeRequest.


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;
}

- I hope this helps!

This was originally posted here.

Comments

*This post is locked for comments