When building your application it is important to consider how deleting a parent record will affect any child or linked records. If you delete a parent record with other records linked to it you are removing the link on the child record and effectively abandoning it with no parent. These orphaned records take up unnecessary space in your database. Best practice is to delete them at the same time you delete the parent record.
Delete Child Records Overview
There are several ways you can delete child records. The easiest way is to create a Background form that filters the child records by the linking column, and then performs the delete task.
Configure the Actions
- On the parent forms' delete task add the store variable action to store the record code of the parent record.
- Create a background form from the child table that filters on the variable stored in step 1.
- On the background form create an onInit() task with the following actions.
- Add the set selection action and configure it to select all records on the form.
- Add the delete action and do not prompt the user.
NOTE: This may be a good place to add the busy indicator.
- Add the close action.
- Add the newly created onInit() task as the on initializing trigger in the background form.
- On the parent forms' delete task, add the Open Form action to open you Background form as hidden after the store variable action. As soon as the background form is opened it will execute the onInit() task you created in step 3 deleting the child records.
- Add the Delete action after the Open Form action to finish by deleting the parent record.
In this example we are going to delete a team record and its related events data.
Configure the Parent Delete Task
Configure the Background onInit() Task