Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 17314

How to: Use Surrogate key, Surrogate Foreing key, Surrogate key replacement fields and Alternate key

$
0
0

A surrogate key is a system-generated value that acts as the primary key of a table. A surrogate key is typically used in place of a set of fields, called the natural key, which would normally act as the primary key of a table.

Have you ever had need to relate two tables using RecId but you have to show a human-readable field instead? (RecId is not one!)

Well, for this we have to use surrogate keys and I will show you step-by-step how to do it using a simple example.

1. Create the table HeaderTable with the following properties

PropertiesValue
NameHeaderTable
Replacement KeyNameIdx (Must Create Index 1st)
Fields:
FieldExtended Data Type
DescriptionDescription
NameName
AccountNumAccountNum

Indexes:

PropertiesValue
NameNameIdx
AllowDuplicatesNo
AlternateKeyYes
PropertiesValue
NameAccountIdx
AllowDuplicatesNo
AlternateKeyNo

Table Structure should look like this:
ScreenClip

3. Now, lets create the Form:

PropertiesValue
NameLineTable

4. Drag and drop the LineTable on form to use it as data source.

5. Create a new Grid on Design and then drag and drop the fields Account.
Important: It should create automatically a Reference Group Control for AccountNum, if you are creating an alternate key for an existing table you have to delete the form field and create a Reference group Control manually.

Form Structure:

ScreenClip

6. Inserting some information on HeaderTable:

ScreenClip

7. Inserting information on LineTable through Form:

ScreenClip

Notice that only the name is shown to user.

8. Let’s check the Line Table

ScreenClip

As you can see the difference, on LineTable form it’s shown to user to select name instead of RecId!
Alternate key is the option to go when you need to use RecId but you have to show a “human-readable” field instead.



Viewing all articles
Browse latest Browse all 17314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>