Bendrinti naudojant


CreateCustomerRelationshipsRequest Class

Definition

Contains the data that is needed to create a new customer lookup column, and optionally, to add it to a specified unmanaged solution.

public ref class CreateCustomerRelationshipsRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
[System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/8.1/Contracts")]
public sealed class CreateCustomerRelationshipsRequest : Microsoft.Xrm.Sdk.OrganizationRequest
[<System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/8.1/Contracts")>]
type CreateCustomerRelationshipsRequest = class
    inherit OrganizationRequest
Public NotInheritable Class CreateCustomerRelationshipsRequest
Inherits OrganizationRequest
Inheritance
CreateCustomerRelationshipsRequest
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>
/// Creates a customer lookup on a table named 'sample_bankaccount'
/// and a solution named 'SolutionName'
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void CreateCustomerRelationships(IOrganizationService service)
{
      string prefix = "sample"; // Solution publisher customization prefix
      // The name of the solution to add the column and relationships to
      string solutionName = "SolutionName";
      // The name of the table to create the customer lookup in.
      string tableLogicalName = $"{prefix}_bankaccount";
      int languagecode = 1033; //English

      CreateCustomerRelationshipsRequest request = new()
      {
         Lookup = new LookupAttributeMetadata
         {
            Description = new Label("The owner of the bank account", languagecode),
            DisplayName = new Label("Account owner", languagecode),
            RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired),
            SchemaName = $"{prefix}_customerid"
         },
         OneToManyRelationships = new OneToManyRelationshipMetadata[]
         {
            new OneToManyRelationshipMetadata()
            {
                  ReferencedEntity = "account",
                  ReferencingEntity = tableLogicalName,
                  SchemaName = $"{prefix}_{tableLogicalName}_customer_account",
            },
            new OneToManyRelationshipMetadata()
            {
                  ReferencedEntity = "contact",
                  ReferencingEntity = tableLogicalName,
                  SchemaName = $"{prefix}_{tableLogicalName}_customer_contact",
            }
         },
         SolutionUniqueName = solutionName
      };

   var response = (CreateCustomerRelationshipsResponse)service.Execute(request);

      Console.WriteLine($"Lookup column ID: {response.AttributeId}");

      Console.WriteLine($"Relationship IDs:");

      response.RelationshipIds.ToList().ForEach(id => {
         Console.WriteLine($"\t- ID: {id}");
      });
}

Output:

Lookup column ID: d38d19a4-62a1-425f-a9dc-dbd310ba5a5d
Relationship IDs:
         - ID: 534920ed-996f-ee11-8df0-000d3a9933c9
         - ID: 5e4920ed-996f-ee11-8df0-000d3a9933c9

Remarks

For the Web API use the CreateCustomerRelationships action.

Usage

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

Privileges and Access Rights

To perform this action, the caller must have the prvCreateAttribute privileges that are granted to the System Administrator and System Customizer security roles.

Notes for Callers

Use the CreateCustomerRelationshipsRequest message to create two table relationships to the lookup column: one to the Account table and the other one to the Contact table. You cannot add relationship to any other entity except for Account and Contact tables.

Supported Tables

You can only add columns to customizable tables where the managed property CanCreateAttributes is true.

Constructors

CreateCustomerRelationshipsRequest()

Initializes a new instance of the CreateCustomerRelationshipsRequest 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)
Lookup

Gets or sets the metadata for the lookup column used to store the ID of the related record. Required.

OneToManyRelationships

Gets or sets the metadata array for the one-to-many relationships to the Account and Contact tables. Required.

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 unmanaged solution to which you want to add this customer lookup column and supporting relationships to. Optional.

Applies to