Compartir por


OrderOptionRequest Class

Definition

Contains the data that is needed to set the order for an option set.

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

This sample shows how to change the order of options in a local option set. The following sample retrieves a PicklistAttributeMetadata column and orders the options by label rather than by value.

/// <summary>
/// Demonstrates OrderOptions message
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void OrderOptionsExample(IOrganizationService service) {

      string tableLogicalName = "account";
      string columnLogicalName = "customertypecode";
      string solutionUniqueName = "SolutionName";
      var columnDefinition = GetLocalChoiceColumn(tableLogicalName, columnLogicalName);

      // Output original order by value
      Console.WriteLine("Original order:");
      OutputOptions(columnDefinition.OptionSet);

      // Order the options by the Label value
      var orderedOptions = columnDefinition.OptionSet.Options
         .OrderBy(x => x.Label.UserLocalizedLabel.Label);

      List<int> newOrder = new();

      foreach (OptionMetadata option in orderedOptions)
      {
         newOrder.Add((int)option.Value);
      }

      // Prepare the request
      OrderOptionRequest request = new() {
         EntityLogicalName = tableLogicalName, // For local choice only
         AttributeLogicalName = columnLogicalName, // For local choice only
         SolutionUniqueName = solutionUniqueName,
         Values = newOrder.ToArray(),
         //OptionSetName = "globalChoiceName" //For global choice only
      };

      // Send the request
      service.Execute(request);

      // Retrieve the column definition again
      columnDefinition = GetLocalChoiceColumn(tableLogicalName, columnLogicalName);

      // Now ordered by Label
      Console.WriteLine("New order:");
      OutputOptions(columnDefinition.OptionSet);


      // Writes the order of the options
      void OutputOptions(OptionSetMetadata options) {
         foreach (OptionMetadata option in options.Options)
         {
            Console.WriteLine($"\t Value:{option.Value} Label:{option.Label.UserLocalizedLabel.Label}");
         }            
      }

      // Retrieves a local Choice column
      PicklistAttributeMetadata GetLocalChoiceColumn(string tableLogicalName, string columnLogicalName) {

         RetrieveAttributeRequest retrieveAttributeRequest = new()
         {
            EntityLogicalName = tableLogicalName,
            LogicalName = columnLogicalName
         };

         var retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);

         return (PicklistAttributeMetadata)retrieveAttributeResponse.AttributeMetadata;
      }
}

Output:

Original order:
   Value:1 Label:Competitor
   Value:2 Label:Consultant
   Value:3 Label:Customer
   Value:4 Label:Investor
   Value:5 Label:Partner
   Value:6 Label:Influencer
   Value:7 Label:Press
   Value:8 Label:Prospect
   Value:9 Label:Reseller
   Value:10 Label:Supplier
   Value:11 Label:Vendor
   Value:12 Label:Other
New order:
   Value:1 Label:Competitor
   Value:2 Label:Consultant
   Value:3 Label:Customer
   Value:6 Label:Influencer
   Value:4 Label:Investor
   Value:12 Label:Other
   Value:5 Label:Partner
   Value:7 Label:Press
   Value:8 Label:Prospect
   Value:9 Label:Reseller
   Value:10 Label:Supplier
   Value:11 Label:Vendor

Sample code on GitHub

Work with choice columns

Remarks

For the Web API use the OrderOption action.

Usage

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

Privileges and Access Rights

To perform this action, the caller must have the System administrator or System customizer security roles.

Notes for Callers

You can use this message to edit options for global option sets or local option sets inside a PicklistAttributeMetadata attribute. For global option sets use the OptionSetName property. For local option sets specify the EntityLogicalName and the AttributeLogicalName.

Constructors

OrderOptionRequest()

Initializes a new instance of the OrderOptionRequest class.

Properties

AttributeLogicalName

Gets or sets the logical name of the PicklistAttributeMetadata local choice column. Optional.

EntityLogicalName

Gets or sets the logical name of the table that contains the local choice column. Optional.

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)
OptionSetName

Gets or sets the name of the global choice you want to edit options for. Optional.

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)
SolutionUniqueName

Gets or sets the name of the solution you want to add the changes to. Optional.

Values

Gets or sets the array of option values in the wanted order. Required.

Applies to