Loading...

Cascade Delete Action in Dynamics 365 FO

Cascade Delete Action in Dynamics 365 FO

When a Delete Action comes into the picture? Normally delete actions come into the picture when a user is trying to delete a database record. Delete actions are used to maintain the data integrity and consistency of the database. At the time of development, a developer must take care of the delete actions to implement in the project.

In Dynamics 365 Finance and Operations (D365 FO), the delete action refers to the deletion of a record from a table in the database.

When a record is deleted, it is permanently removed from the system and cannot be recovered. Therefore, it is important to exercise caution when performing this action and ensure that it is necessary and appropriate to do so. In D365 FO, the Deleted action can be performed using various methods, including:

  • Using the "Delete" button on a record's form.
  • Using the "Delete" command on a record's right-click menu.
  • Using X++ code to delete records programmatically.

It is important to note that some records in D365 FO cannot be deleted due to system constraints or dependencies on other records. In such cases, the system will prevent the deletion and display an error message. A delete action is performed when related tables are existing in the project, and deleting records from any table must be restricted for keeping the database consistent.

Imagine we have two tables. One is a product category table with the name PrdCategoryTable and another is a product table with the name PrdTable. Where PrdCategoryTable stores different product categories, and PrdTable stores the details of different products. PrdTable refers CategoryId of PrdCategoryTable as the reference key. So PrdCategoryTable is the parent table and PrdTable is the child table. PrdTable alone has no existence without PrdCategoryTable.  So, deleting any records from both tables must be restricted.

In Microsoft Dynamics 365 Finance & Operations, there are four types of Delete Actions.

  • None.
  • Cascade.
  • Restricted.
  • Cascade + Restricted

Read more: What are the different types of delete actions in Dynamics 365 fo

All four Delete Action methods have major roles in Dynamics 365 development process. In this article, I am going to explain the cascade deletion action property with a simple example.

Cascade delete Action.

In Dynamics 365 Finance and Operations, the cascade delete action refers to a feature that enables the automatic deletion of related records when a parent record is deleted. It is a database-level functionality that helps maintain data integrity and ensures that the database remains consistent.

When you configure a relationship between tables/entities in Dynamics 365 Finance and Operations, you can define the cascade delete action for that relationship. 

Setting up the Delete Action property to Cascade extends the functionality of Tables' delete method. The Cascade Delete action deletes all the records in the related tables where the primary key is equivalent to the primary key of the parent table. which means that deleting records from the parent table also deleting the child records from the child table where the primary key of the parent table matches the foreign key of the child table without any warning.

Add Cascade Delete Action in Dynamics 365 FO

At the time of development, a developer must take care of the delete actions to implement in the project. Here I will show you how to set a Cascade delete action in Dynamics 365 Finance and Operations. For this,

1. Create a normal relation

Imagine we have two tables one is a product category table with the name PrdCategoryTable which has three columns CategoryId, CategoryCode, and CategoryName, and another product table with the name PrdTable, which has four columns PrdId, PartNumber, Description, and CategoryId where PrdCategoryTable stores different product categories, and PrdTable stores the product details. Here PrdCategoryTable is the parent table and PrdTable is the child table.

PrdTable refers CategoryId of PrdCategoryTable as the reference key. PrdTable alone has no existence without PrdCategoryTable.

Once you created these two tables, you can read the article on how to create a normal relation in Dynamics 365 fo,

After creating the normal relationship between the above tables, we need to set the cascade delete action to the table, for best practice, you always set the delete action in the parent table.

Add a cascade delete action

For setting up the cascade delete action, you need to follow the below steps,

1. Expand the parent table PrdCategoryTable. Find the delete action node, and right-click delete actions.

Cascade Delete Action in Dynamics 365 FO
2. Then click New Delete Action and right-click the new delete action, and then click Properties.
Cascade Delete Action in Dynamics 365 FO
3. Select a related table in the table reference property from the Table property list. In our example select PrdTable. Select action property as Cascade.
Cascade Delete Action in Dynamics 365 FO

This is the basic setup for adding cascade delete action in Dynamics 365 finance and operations. Once you have done all the above steps, you need to build the project successfully. After the successful build of the project, Right-click on the table PrdCategoryTable and select Open Table Browser to open the table in the browser.

Wait for a minute, a table browser will open in the browser, and you can enter some dummy data into the PrdCategoryTable as shown in the below figure.

Cascade Delete Action in Dynamics 365 FO

Similarly, Right click on the table PrdTable and select Open Table Browser to open the table in the browser.

Wait for a minute, a table browser will open in the browser, and you can add some dummy data into the PrdTable as shown in the below figure. here I added some product records by referring to the CategoryId 1000 from the table PrdCategoryTable.

Cascade Delete Action in Dynamics 365 FO

Now we are going to test the delete action applied to the tables. For this, Delete a record from the parent table

Cascade Delete Action in Dynamics 365 FO

Here I deleted one record from PrdCategoryTable with CategoryId as "1000", because PrdTable refers to the category id 1000. If the deletion action is set or working properly, it will automatically delete the related data from the child table PrdTable.

Open the child table PrdTable and refresh the browser to refresh the data in the PrdTable. Now you can see all the related records from the child table PrdTable has been deleted automatically. Yes, the related records are automatically deleted from the child table, and the cascade deletes action is working properly.

Cascade Delete Action in Dynamics 365 FO

I think this article will be very useful for beginners and if the article is useful, please try to share it with your friends who are planning a career in D365 FO. In the next article, I will show you how to add restricted delete action in Dynamics 365 fo.

Published on:

Learn more
D365 Snippets
D365 Snippets

Share post:

Related posts

Interview Questions and Answers Dynamics 365 CE and Power Platform – Ultimate Guide

In today's business landscape, Dynamics 365 Customer Engagement (CE) and the Power Platform have emerged as game-changing tools that have tran...

6 days ago

Back to Basics # 72: Limit Special Characters Using a Webresource in Dynamics CRM

Recently we got a requirement to restrict user to enter special characters. Step 1 : Use the below method for restricting special characters S...

14 days ago

20 Most commonly used JavaScript Scenarios with Sample code Snippet in Form Script Dataverse/ Dynamics 365 CE

JavaScript is a powerful tool for developers working with Dataverse (formerly known as Common Data Service) and Dynamics 365 Customer Engageme...

26 days ago

New and Retired Microsoft Dynamics 365 Certifications

Microsoft has recently shared updates regarding new and retired certifications for Microsoft Dynamics 365. This post provides an overview of t...

27 days ago

Embed a Power BI Report as a System Dashboard in Dynamics 365 CE Using Environment Variables

Integrating Power BI with Dynamics 365 CE can elevate your decision-making processes by providing seamless access to actionable insights. This...

28 days ago

How to amplify contact centers and field service operations with AI

In this video, Jeff Comstock, Corporate Vice President of Dynamics 365 Customer Service, discusses the transformative power of Copilot in enha...

1 month ago

Decrement field value automatically using workflow in dataverse or dynamics 365

In Dataverse (formerly known as Common Data Service) or Dynamics 365, you can automate the decrementing of a field value using workflows. With...

1 month ago

Fuzzy Matching to Eliminate Duplicates in Dynamics 365 CRM with DeDupeD!

If you're struggling with "fuzzy duplicates" in your Dynamics 365 CRM, the solution is here! Meet DeDupeD, the tool designed to eliminate chao...

1 month ago

{How to} Configure custom card for the inbox dynamics 365 Omnichannel

If you're looking to configure custom card settings for your inbox on Dynamics 365 Omnichannel, then this tutorial is for you. In it, you'll l...

1 month ago

{Do you know} Create mulitple cases from email sent to multiple mailboxes in Dynamics 365 Omnichannel

If you're looking to create multiple cases from an email sent to multiple mailboxes in Dynamics 365 Omnichannel, this post has got you covered...

1 month ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy