AX2012/D365FnO – HOW TO CREATE A FOREIGN KEY RELATIONSHIP BETWEEN TWO TABLES IN D365FnO

D365fno-PostImage

In this blog post, I will show you how to create a foreign key relationship between two tables in D365FnO.

A foreign key ensures that the values in the referencing (Child) table match the values in the referenced (Parent) table. A one-to-many relationship is a type of foreign key relationship where one record in the referenced table can have many related records in the referencing table.

To create a foreign key relationship at the table level, you need to follow these steps:
 
1. Open the Application Object Tree and expand the Data Dictionary node.
2. Find and select the referencing table that you want to add the foreign key to. Right-click on the table and select New > Foreign Key Relation.
 
New foreign key relation on table

3. In the Properties window, set the Name property to a meaningful name for the relation. For example, if you want to create a relation between CustomerGroup and CustomerTable, you can name it CustomerGroup.
4. Set the Table property to the name of the referenced (Parent) table. For example, CustomerGroup.
5. Set the Cardinality property to ZeroMore. This indicates that referencing (Child) table can have zero or more records.

  • Cardinality: Referencing table records existence (ZeroMore)
  • Name: Usually used referenced table name (CustomerGroup).
  • Index: Referenced (Parent) table primary index.
  • On Delete: If set the On-Delete property to Restricted warring will be generated if the child table exists any record.
  • Related Table: Select the referenced table from the drop-down.
  • Related Table Cardinality: Referenced table record existence ExectlyOne in case of parent table have only one record like Group.
  • Relationship Type: Association is a strong type of foreign key relationship with parent and child tables.

6. Right-click on the relation name (CustomerGroup) and Select New > Normal.
7. In the Properties window, set the Field property to the name of the field in the referencing table that contains the foreign key value. For example, CustomerGroup.
8. Set the RelatedField property to the name of the field in the referenced table that contains the primary key value. For example, CustomerGroupId.
9. Save and synchronize your changes.

I hope this blog post was helpful for you to learn how to create a foreign key relation on the table in D365FnO with some best practices. Thank you for reading!

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.