Partilhar via


InsertOptionValueRequest Class

Definition

Contains the data that is needed to insert a new option value for a global choice or local choice column.

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

Examples

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

This example shows how to add a new option to the account.accountcategorycode local choice column.

/// <summary>
/// Demonstrates adding a local option value
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void InsertLocalOptionValueExample(IOrganizationService service)
{

      int languageCode = 1033; //English
      string solutionUniqueName = "SolutionName";
      string tableLogicalName = "account";
      string columnLogicalName = "accountcategorycode";
      string labelText = "VIP";
      string optionDescriptionLabel = "VIP customer";

      // Create a request.
      InsertOptionValueRequest request = new()
      {
         AttributeLogicalName = columnLogicalName,
         EntityLogicalName = tableLogicalName,
         Label = new Label(labelText, languageCode),
         Description = new Label(optionDescriptionLabel, languageCode),
         SolutionUniqueName = solutionUniqueName
         // Value = 3, Recommend to let system set value
      };

      // Send the request:
      var response = (InsertOptionValueResponse)service.Execute(request);

      Console.WriteLine($"The new option value is {response.NewOptionValue}.");
}

Output:

The new option value is 152960000.

The following example shows how to insert a new option into a global option.

/// <summary>
/// Demonstrates adding a Global option value
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void InsertGlobalOptionValueExample(IOrganizationService service)
{

      int languageCode = 1033; //English
      string solutionUniqueName = "SolutionName";
      string choiceName = "samples_example";
      string labelText = "Choice Two";
      string optionDescriptionLabel = "The second choice.";

      // Create a request.
      InsertOptionValueRequest request = new()
      {
         OptionSetName = choiceName,
         Label = new Label(labelText, languageCode),
         Description = new Label(optionDescriptionLabel, languageCode),
         SolutionUniqueName = solutionUniqueName
         // Value = 3, Recommend to let system set value
      };

      // Send the request:
      var response = (InsertOptionValueResponse)service.Execute(request);

      Console.WriteLine($"The new option value is {response.NewOptionValue}");
}         

Output:

The new option value is 152960001.

Sample code on GitHub

Work with choice columns

Remarks

For the Web API use the InsertOptionValue action.

Usage

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

Privileges and Access Rights

To perform this action, the caller must have the prvWriteOptionSet privilege that is included in the System administrator and System customizer security roles.

Notes for Callers

Use this message to update global choices or local choice columns.

When you update a global option set only the Label and OptionSetName properties are required.

When you update a local option set, only AttributeLogicalName, EntityLogicalName, and Label properties are required.

Constructors

InsertOptionValueRequest()

Initializes a new instance of the InsertOptionValueRequest class

Properties

AttributeLogicalName

Gets or sets the name of the column when updating a local choice column. Optional.

Description

Gets or sets a description for the option. Optional.

EntityLogicalName

Gets or sets the table logical name when updating the local option set in a 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)
Label

Gets or sets the label for the option. Required.

OptionSetName

Gets or sets the name of the global option set. Optional.

Parameters

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

(Inherited from OrganizationRequest)
ParentValues

For internal use only.

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 unique name of the unmanaged solution when updating a choice. Optional.

Value

Gets or sets the value for the option. Optional.

Applies to