Understanding Primary Key, Alternate Keys, and Primary Column in Dynamics 365

 

Understanding Primary Key, Alternate Keys, and Primary Column in Dynamics 365

Dynamics 365 offers various ways to uniquely identify and display records, which are important for data integrity, performance, and user experience. In this article, we'll explore the differences between Primary Key, Alternate Keys, and Primary Column, along with examples for each.

Primary Key

Definition

The Primary Key is a system-generated Globally Unique Identifier (GUID) that serves to uniquely identify each record in a table. This is the backbone of data integrity and is used for database-level operations.

Features

  1. Uniqueness: Always unique for each record.
  2. System-Generated: Automatically created by Dynamics 365.
  3. Immutability: Cannot be changed once the record is created.

Example: Record Retrieval in C#

C#
// Assuming service is an established IOrganizationService Entity myRecord = service.Retrieve("contact", new Guid("GUID_HERE"), new ColumnSet(true));

Alternate Keys (Keys)


Definition

Alternate Keys are additional fields or sets of fields that you can configure to be unique. They are often used for integration scenarios with external systems.

Features

  1. Custom-Defined: Can be user-defined fields.
  2. Uniqueness: Enforces that the specified field(s) are unique across the table.
  3. Lookup & Integration: Useful for record matching when integrating with other systems.

Example: Record Retrieval Using Alternate Key in C#

C#
// Initialize the service proxy IOrganizationService service = GetOrganizationService(); // Assume GetOrganizationService() gets you a connected service // Define the alternate key AlternateKey alternateKey = new AlternateKey { EntityLogicalName = "contact", KeyAttributes = { new KeyValuePair<string, object>("new_CustomerNumber", "12345") } }; // Retrieve the record using the alternate key Entity contact = service.Retrieve(alternateKey);

Primary Column


Definition

The Primary Column is the main field used to display the record in the application. It is not necessarily unique and is often used for human-readable identification of records.

Features

  1. User-Friendly: Provides a readable identifier for the records.
  2. Not Unique: Can contain duplicate values.
  3. Search & Display: Often used in search and navigation features.

Example: Setting Primary Column in Custom Table

  1. Navigate to Settings -> Customizations -> Customize the System.
  2. Go to Tables, and find your custom table.
  3. Under the General tab, specify the "Primary Field" as your desired field, e.g., "Name".

Key Takeaways

  1. Primary Key: Always unique, system-generated, and immutable. Used for database-level operations.
  2. Alternate Keys (Keys): Custom-defined, unique, and often used in integration scenarios.
  3. Primary Column: User-friendly, not necessarily unique, and used for display and navigation in the application.

By understanding these different ways of identifying and displaying records, you can make more informed decisions when designing and integrating your Dynamics 365 solution.

No comments:

Post a Comment