OrderOptionRequest Class
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online
Contains the data that is needed to set the order for an option set.
For the Web API use the OrderOption Action.
Namespace: Microsoft.Xrm.Sdk.Messages
Assembly: Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)
Inheritance Hierarchy
System.Object
Microsoft.Xrm.Sdk.OrganizationRequest
Microsoft.Xrm.Sdk.Messages.OrderOptionRequest
Syntax
[DataContractAttribute(Namespace = "https://schemas.microsoft.com/xrm/2011/Contracts")]
public sealed class OrderOptionRequest : OrganizationRequest
<DataContractAttribute(Namespace := "https://schemas.microsoft.com/xrm/2011/Contracts")>
Public NotInheritable Class OrderOptionRequest
Inherits OrganizationRequest
Constructors
Name | Description | |
---|---|---|
OrderOptionRequest() | Initializes a new instance of the OrderOptionRequest class |
Properties
Name | Description | |
---|---|---|
AttributeLogicalName | Gets or sets the logical name of the PicklistAttributeMetadata attribute. Optional. |
|
EntityLogicalName | Gets or sets the logical name of the entity that contains the attribute. 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 option set 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 an asynchronous operation (system job). 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 solution component to. Optional. |
|
Values | Gets or sets the array of option values in the wanted order. Required. |
Methods
Name | Description | |
---|---|---|
Equals(Object) | (Inherited from Object.) |
|
GetHashCode() | (Inherited from Object.) |
|
GetType() | (Inherited from Object.) |
|
ToString() | (Inherited from Object.) |
Remarks
Message Availability
For this message to work, the caller must be connected to the server.
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 message 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.
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 IOrganizationServiceinterface. For the complete sample, see the link later in this topic.
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");
' Use the RetrieveAttributeRequest message to retrieve
' a attribute by it's logical name.
Dim retrieveAttributeRequest As RetrieveAttributeRequest = New RetrieveAttributeRequest With {
.EntityLogicalName = Contact.EntityLogicalName,
.LogicalName = "new_picklist",
.RetrieveAsIfPublished = True}
' Execute the request.
Dim retrieveAttributeResponse As RetrieveAttributeResponse = CType(_serviceProxy.Execute(retrieveAttributeRequest), RetrieveAttributeResponse)
' Access the retrieved attribute.
Dim retrievedPicklistAttributeMetadata As PicklistAttributeMetadata = CType(retrieveAttributeResponse.AttributeMetadata, PicklistAttributeMetadata)
' Get the current options list for the retrieved attribute.
Dim optionList() As OptionMetadata = 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:
Dim updateOptionList = optionList.OrderBy(Function(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.
Dim orderOptionRequest As OrderOptionRequest = New OrderOptionRequest With {
.AttributeLogicalName = "new_picklist",
.EntityLogicalName = Contact.EntityLogicalName,
.Values = updateOptionList.Select(Function(x) x.Value.Value).ToArray()}
' Set the properties for the request.
' Set the changed order using Select linq function
' to get only values in an array from the changed option list.
' Execute the request
_serviceProxy.Execute(orderOptionRequest)
Console.WriteLine("Option Set option order changed")
Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Microsoft.Xrm.Sdk.Messages Namespace
Sample: Work with attribute metadata
Customize entity attribute metadata
Return to top
Microsoft Dynamics 365
© 2016 Microsoft. All rights reserved. Copyright