This is a method that you can use to retrieve a Global Optionset list of values with C#, it works for CRM 2011, 2013 and 2015.
/// <summary>
/// Method to retrieve global optionset metadata values
/// </summary>
/// <param name="_serviceProxy">CRM Service instance</param>
/// <param name="_globalOptionSetName">Global Optionset name</param>
/// <returns>Returns the global optionset metadata values</returns>
private OptionMetadata[] GetGlobalOptionsetValues(OrganizationServiceProxy _serviceProxy, string _globalOptionSetName)
{
OptionMetadata[] result = null;
// Use the RetrieveOptionSetRequest message to retrieve
// a global option set by it's name.
RetrieveOptionSetRequest retrieveOptionSetRequest = new RetrieveOptionSetRequest(){ Name = _globalOptionSetName };
// Execute the request.
RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)_serviceProxy.Execute(retrieveOptionSetRequest);
// Access the retrieved OptionSetMetadata.
OptionSetMetadata retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;
// Get the current options list for the retrieved attribute.
result = retrievedOptionSetMetadata.Options.ToArray();
return result;
}
No comments:
Post a Comment