Delete actions

From Axaptapedia

Adding a delete action
Enlarge
Adding a delete action

Delete actions on a table are used for two purposes

  • Restrict the deletion of a record based on related records in another table
  • Cascade the deletion of a record to related tables to ensure data-consistency

The Restrict component of a delete action occurs during the call to .validateWrite() on the table. If a deletion is performed from a form, then this method is called automatically. From code however, the delete restriction will have no effect unless the programmer explicitly calls .validateDelete() and checks the return value before deciding whether to go ahead with the deletion.

Contents

Adding a delete action

Delete actions are added in the AOT, by right-clicking on the DeleteActions node of a Table AOT element. Select New DeleteAction and then select the table on which this delete action will be based.

There are three different types of delete actions

  1. Cascade
  2. Restricted
  3. Cascade+Restricted

Types of delete action

Cascade

A cascading deletion action will delete all records in the related table, where the foreign key is equivalent to the primary key of the current table. That is, deleting the parent record will also delete the child record(s) in the related table.

This cascading will take place whether the deletion is performed in code or directly by a user through the user interface.

Restricted

A restricting delete action will raise an error message if the user tries to delete a record, where records exist in the related table where the foreign key is equivalent to the primary key of the current table.

This error will only appear if the deletion is performed through the user interface. A deletion from X++ code will be allowed to proceed and will not be cascaded to the related table. In this case the programmer should call .validateDelete() themselves prior to the call to .delete()

Cascade+Restricted

This delete action normally works as a Restricted delete action. However if the deletion is performed through X++ code, no error will be raised and the deletion will be cascaded to the related table.