Truncating a table

This is included here to explain what this does, so that we don't do it.

This is the second most powerful and scary function in AX, the second easy function using which we can delete a legal entity.

The SQL statement will be used to truncate the table, so data in all companies is deleted using an SQL command, and all AX validation, triggers, and any other business logic are not run. This can leave you with orphaned records in the system.

Note

In 13 years I have used this function just once.

In this case, just be aware of the command and don't follow along on this task!

Getting ready

Log in to AX as a system administrator.

I have created a TestTable table and overridden the validateDelete method so that it doesn't allow the record to be deleted. Furthermore, I have modified the delete method so that this also generates an error and does not call super() (xRecord.doDelete()), as given in the following code:

public boolean validateDelete()
{
    return checkFailed("Cannot delete this record");
}
public void delete()
{
    error("Cannot delete records in this table.");
    //super();
}

If we try to delete this table from a form, we will receive the error, Cannot delete this record. If you try to delete it from code, you will receive the error, Cannot delete records in this table, and since super is not called, the database operation is not performed.

How to do it...

To truncate a table, follow these steps:

  1. Navigate to System administration | Periodic | Database | SQL administration.
  2. Expand All tables.
  3. Select a table, for example, TestTable.
  4. Click on Table actions and select Truncate table.
  5. On the warning that pops up, click on Yes (double check if you have selected the correct table!)

    Note

    AX will warn you that this will delete all records in all companies. This includes all partitions as well!

  6. Almost immediately after the process is completed, the validation errors will not be displayed.

How it works...

This is done at SQL level, completely bypassing AX business logic. This is how it is allowed to delete records in another partition.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.93.137