It is critical that we enforce data integrity on the tables we create. AX assists us a lot with this by creating relations. AX will use the relations we created earlier to ensure that data entered through the user interface is valid. Simply put, we can only enter a vehicle group on the vehicle table that exists in the vehicle group table. It is more accurate in this example to say that the data entered in the vehicle group field is validated against the relation; the relation might have an additional constraint.
AX handles that data entry validation, but what happens when we want to delete a vehicle group? The system cannot know the answer to this because we have different scenarios here, as shown in the following table:
Foreign table |
Related table |
Action |
---|---|---|
|
|
Restrict deletion |
|
|
Restrict deletion |
|
|
Cascade |
This is what delete actions are used for—to define this behavior. We configure this in the foreign table as per the following steps:
ConFMSVehicleGroup
table, right-click and select New DeleteAction.ConFMSVehicleTable
in the Table property (paying attention to autocompletion).ConFMSVehicleSchedule
> ConFMSVehicleTable
.ConFMSVehicleTable
> ConFMSVehServiceTable
, but make DeleteAction property Cascade
.The delete action has the following options, None
, Restricted
, Cascade
, Cascade + Restricted
:
None
: This has no effect, and effectively disables the delete action. This is useful if you want to specifically state "do nothing" so that someone else doesn't try to correct what seems to be an omission.Restricted
: This will prevent the record from being deleted if there are records in the related table that match the selected relation. This occurs within the validateDelete
table event, which is called by the delete
table event.Cascade
: This will delete the record in the related table, based on the relation. A sales order line is of no use without a sales order. This is an extension of the delete
table event.Cascade + Restricted
: This is a little special. In a two-table scenario, it is the same as Restricted. It will stop the record from being deleted if a related record exists. But if the record is being deleted as part of a cascade from a table related to it, the records will be deleted.See How to: Create Delete Actions at http://msdn.microsoft.com/en-us/library/bb315018.aspx.
For example, in the following scenario we have invented a grandparent table above ConFMSVehicleTable
, called ConFMSHaulierTable
:
If we try to delete a record from ConFMSVehicleTable
and there are related records in ConFMSVehServiceTable
, the deletion will not be allowed.
If we delete a record from ConFMSHaulierTable
, it will also delete related records in ConFMSVehicleTable
and cascade the deletion so that the related ConFMSVehServiceTable
records will be deleted as well.
3.144.227.9