Search code examples
c#dynamics-crmdynamics-crm-2011

Retrieve Optionsets in Dynamics 2011


I am using this code to retrieve global optionsets

var request = new RetrieveOptionSetRequest {Name = "OptionsetNameGoesHere"};
var retrieveOptionSetResponse =(RetrieveOptionSetResponse) DynamicsHandler._serviceProxy.Execute(request);
var retrievedOptionSetMetadata =(OptionSetMetadata) retrieveOptionSetResponse.OptionSetMetadata;
var optionList = retrievedOptionSetMetadata.Options.ToArray();

foreach (var optionMetadata in optionList)
{
   Printout(optionMetadata.Label.LocalizedLabels[0].Label + "\n");
}

But how do I retrieve optionsets like AccountCategory (AccountCategoryCode) so that I can bind them to a Combobox?


Solution

  • You should get it with a RetrieveAttributeRequest. It will return an RetrieveAttributeResponse which contains the Property AttributeMetadata.

    In your case it should be of type OptionSetMetadata, which is what you are looking for.