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
1. Expand the parent table PrdCategoryTable. Find the delete action node, and right-click delete actions.
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.
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.
Now we are going to test the delete action applied to the tables. For this, Delete a record from the parent table
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.
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 moreRelated posts
Dynamics 365 CE Solution Import Failed in Azure DevOps Pipelines
Got the below error while importing Dynamics CRM Solution via Azure DevOps Pipeline. 2024-12-18T23:14:20.4630775Z ]2024-12-18T23:14:20.74...
Exploring the Differences: Managed vs. Unmanaged Solutions in Dynamics CRM/Dataverse
In Dynamics CRM/Dataverse, solutions are central to Application Lifecycle Management (ALM), providing a structured way to manage, package, and...
Effective Strategies for Debugging Plugins in Dynamics CRM
In a recent interview, I was asked about debugging plugins in Dynamics CRM. The interviewer specifically wanted to know my approach to plugin ...
Is Microsoft Dynamics CRM Affordable for Small Nonprofits?
Satish Reddy By Satish Reddy | Reading time 6 mins When considering a CRM solution, affordability is often a primary concern for small no...
How Microsoft Dynamics CRM Services Helps a Startup Nonprofit
Satish Reddy By Satish Reddy | Reading time 6 mins For startup nonprofits, the right Customer Relationship Management (CRM) system can be...
Easy Plugin Registration Tool Installation for Dynamics 365 CE Developers
Hi Folks, Are you a Power Platform or Dynamics 365 CE Developer, you would definitely need to work on Plugin Registration tool at any given po...
Web resource method does not exist in Dynamics 365 CE
Got the below error while working on Onload of Account record JavaScript in Microsoft Dynamics 365 CE. Script Error One of the scripts for thi...
How to get Environment Variable Value in Dynamics 365 CE using JavaScript?
We might have got a scenario to use the Environment Variable Value in the JavaScript in Dynamics 365 CE. In this article, will explain about r...
Enhancing Business Efficiency with Dynamics 365 CE/CRM AI Capabilities
Artificial intelligence (AI) is a vital catalyst for business transformations in this digital era. A leading player in this revolution
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...