Partekatu honen bidez:


Clase de OrderOptionRequest

Se aplica a: CRM 2015 on-prem, CRM Online

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

Espacio de nombres: Microsoft.Xrm.Sdk.Messages
Ensamblado: Microsoft.Xrm.Sdk (en Microsoft.Xrm.Sdk.dll)

Sintaxis

'Declaración
<DataContractAttribute(Namespace:="https://schemas.microsoft.com/xrm/2011/Contracts")> _
Public NotInheritable Class OrderOptionRequest
    Inherits OrganizationRequest
[DataContractAttribute(Namespace="https://schemas.microsoft.com/xrm/2011/Contracts")] 
public sealed class OrderOptionRequest : OrganizationRequest

Ejemplo

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 IOrganizationServiceinterfaz. Para la muestra completa, vea el vínculo más adelante en este tema.

This sample shows how to change the order of options in a local option set. The following sample retrieves a custom PicklistAttributeMetadata attribute and changes the order of the original options using the OrderBy LINQ function to sort items in ascending order by the label text. Then it uses OrderOptionRequest to set the new order of the options for the attribute.

Use the OrderByDecending LINQ function to order the items in descending order.

// Use the RetrieveAttributeRequest message to retrieve  
// a attribute by it's logical name.
RetrieveAttributeRequest retrieveAttributeRequest =
    new RetrieveAttributeRequest
{
    EntityLogicalName = Contact.EntityLogicalName,
    LogicalName = "new_picklist",
    RetrieveAsIfPublished = true
};

// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =
    (RetrieveAttributeResponse)_serviceProxy.Execute(
    retrieveAttributeRequest);

// Access the retrieved attribute.
PicklistAttributeMetadata retrievedPicklistAttributeMetadata =
    (PicklistAttributeMetadata)
    retrieveAttributeResponse.AttributeMetadata;

// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
    retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();

// Change the order of the original option's list.
// Use the OrderBy (OrderByDescending) linq function to sort options in  
// ascending (descending) order according to label text.
// For ascending order use this:
var updateOptionList =
    optionList.OrderBy(x => x.Label.LocalizedLabels[0].Label).ToList();

// For descending order use this:
// var updateOptionList =
//      optionList.OrderByDescending(
//      x => x.Label.LocalizedLabels[0].Label).ToList();

// Create the request.
OrderOptionRequest orderOptionRequest = new OrderOptionRequest
{
    // Set the properties for the request.
    AttributeLogicalName = "new_picklist",
    EntityLogicalName = Contact.EntityLogicalName,
    // Set the changed order using Select linq function 
    // to get only values in an array from the changed option list.
    Values = updateOptionList.Select(x => x.Value.Value).ToArray()
};

// Execute the request
_serviceProxy.Execute(orderOptionRequest);

Console.WriteLine("Option Set option order changed");

Comentarios

Message Availability

Para que este mensaje funcione, el autor de la llamada debe estar conectado al servidor.

Usage

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

Privileges and Access Rights

To perform this action, the caller must have privileges listed in OrderOption Privileges.

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.

Jerarquía heredada

System.Object
   Microsoft.Xrm.Sdk.OrganizationRequest
    Microsoft.Xrm.Sdk.Messages.OrderOptionRequest

Seguridad de hilo

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para el hilo. No se garantiza que los miembros de instancia sean seguros para el hilo.

Plataformas

Plataformas de desarrollo

Windows Vista, Windows Server 2003 y

Plataformas de destino

Windows Vista,Windows XP

Change History

Vea también

Referencia

Miembros de OrderOptionRequest
Espacio de nombres de Microsoft.Xrm.Sdk.Messages

Otros recursos

Sample: Work with Attributes
Customize Entity Attribute Metadata

Send comments about this topic to Microsoft.
© 2014 Microsoft Corporation. All rights reserved.