Delen via


RetrieveAllOptionSetsRequest Class

Definition

Contains the data that is needed to retrieve information about all global choices.

public ref class RetrieveAllOptionSetsRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
[System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")]
public sealed class RetrieveAllOptionSetsRequest : Microsoft.Xrm.Sdk.OrganizationRequest
[<System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")>]
type RetrieveAllOptionSetsRequest = class
    inherit OrganizationRequest
Public NotInheritable Class RetrieveAllOptionSetsRequest
Inherits OrganizationRequest
Inheritance
RetrieveAllOptionSetsRequest
Attributes

Examples

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface instance.

/// <summary>
/// Retrieves all global choice definitions
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void RetrieveAllOptionSets(IOrganizationService service)
{

    RetrieveAllOptionSetsRequest request = new();
    var response = (RetrieveAllOptionSetsResponse)service.Execute(request);

    var orderedGlobalChoices = response.OptionSetMetadata.OrderBy(m => m.Name);

    foreach (OptionSetMetadataBase item in orderedGlobalChoices)
    {
        Console.WriteLine($"{item.Name}:");
        switch (item.OptionSetType)
        {
            case OptionSetType.Picklist:

                foreach (OptionMetadata option in ((OptionSetMetadata)item).Options)
                {
                    Console.WriteLine($"\t{option.Value}:{option.Label.UserLocalizedLabel.Label}");
                }
                break;
            case OptionSetType.State:
            case OptionSetType.Status:
                // These are only defined in local choice columns.
                break;
            case OptionSetType.Boolean:
                OptionMetadata trueOption = ((BooleanOptionSetMetadata)item).TrueOption;
                Console.WriteLine($"\t{trueOption.Value}:{trueOption.Label.UserLocalizedLabel.Label}");
                OptionMetadata falseOption = ((BooleanOptionSetMetadata)item).FalseOption;
                Console.WriteLine($"\t{falseOption.Value}:{falseOption.Label.UserLocalizedLabel.Label}");
                break;
        }
    }
}

Sample output:

activity_mailmergetypecode:
  4210:Phone Call
  4201:Appointment
  4207:Letter
  42070:Letter via Mail Merge
  4204:Fax
  42040:Fax via Mail Merge
  4202:Email
  42020:Email via Mail Merge
activity_typecode:
  4210:Phone Call
  4201:Appointment
  4207:Letter
  4204:Fax
  4202:Email

< results limited for brevity >

activitypointer_isemailfollowed:
        1:Yes
        0:No
activitypointer_isregularactivity:
        1:Yes
        0:No

< results limited for brevity >

Sample code on GitHub

Work with choice columns

Remarks

Usage

Pass an instance of this class to the Execute(OrganizationRequest) method, which returns an instance of RetrieveAllOptionSetsResponse.

Privileges and Access Rights

Global choice definition data is available for all users.

Notes for Callers

This operation will not return options defined locally for a column, including statecode and statuscode columns. Only global (re-usable) choice definitions are returned. Learn to insert, update, delete, and order global choices

Constructors

RetrieveAllOptionSetsRequest()

Initializes a new instance of the RetrieveAllOptionSetsRequest class.

Properties

ExtensionData

Gets or sets the structure that contains extra data. Optional.

(Inherited from OrganizationRequest)
Item[String]

Gets or sets the indexer for the Parameters collection.

(Inherited from OrganizationRequest)
Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RequestId

Gets or sets the ID of the request. Optional.

(Inherited from OrganizationRequest)
RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RetrieveAsIfPublished

Gets or sets whether to retrieve the metadata that has not been published. Required.

Applies to