Axaptapedia is now maintained by AgileCadence For more information please click here.
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 .validateDelete() 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. The Cascade component of a delete action occurs during the call to .delete() on the table. There exists also a property skipDeleteActions(boolean) which changes the behaviour of the validateDelete() and of the delete()-Methods.
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 four different types of delete actions
Types of delete action
A None deletion action will delete selected row in the table but nothing occurs to the table that relate to this table.
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.
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()
The delete action performs an restricted, if the record of the table will be deleted directly and performs an cascade, if the record of the table will be deleted through a cascade delete action of a other table. e.g.: tableA (Customer) (a cascade deleteaction to tableB) tableB (SalesOrder) (a cascade+restricted deleteaction to tableC) tableC (SalesLine)
When a record of tableB will be deleted, the restricted part of the deleteaction will be performed. The record of tableB can only be deleted, if no record in tableC exist for the record in tableB. (The SalesOrder can only be deleted, if no SalesLine exist for the SalesOrder).
A record in tableA will be deleted, so the cascade deleteaction to tableB will be performed. In this case, the cascade part of the deleteaction to tableC will be performed. (When a Customer will be deleted, the SalesOrders and SalesLines will also be deleted)
So, the performing action of a cascade+restriced deleteaction depends on the kind of deletion of the record. (direct:restricted, cascading:cascade)