Thursday, April 20, 2023

Delete actions in Dynamics 365 FO

 In Microsoft Dynamics 365 Finance and Operations (F&O), there are several types of delete actions that help maintain data integrity across related tables. These actions define how the system should behave when a record in the primary table is deleted. Here are the main types of delete actions:


1. No action: No action is taken when a record is deleted in the primary table. This means that related records in the secondary table will remain unchanged, which may lead to orphaned records.


2. Cascade: When a record is deleted in the primary table, all related records in the secondary table are also deleted. This ensures that no orphaned records are left behind, maintaining referential integrity.


3. Restricted: If there are related records in the secondary table, the system prevents the deletion of the record in the primary table. This ensures that all related records are addressed before the primary record can be deleted.


4. Cascade + Restricted: This is a combination of the Cascade and Restricted actions. If there are no related records in the secondary table, the primary record can be deleted. If there are related records, the system will first attempt to cascade delete the related records. If any of the related records cannot be deleted due to other restrictions, the system will prevent the deletion of the primary record. Example : Imagine you have two tables: a "Customers" table and an "Orders" table. The Customers table contains information about your customers, and the Orders table stores their orders.

Now, let's say you want to delete a customer record from the Customers table. With the Cascade + Restricted delete action, the system will check if there are any orders associated with that customer in the Orders table.

a. If there are no related orders, the customer record will be deleted without any issues.

b. If there are related orders, the system will attempt to delete all those orders first (Cascade).

c. If any of the related orders cannot be deleted due to restrictions (like dependencies on other tables), the system will prevent you from deleting the customer record (Restricted).

In this way, the Cascade + Restricted delete action ensures that all related records are either deleted or addressed before deleting the primary record, maintaining data integrity and avoiding potential issues.