Normally, during the testing stage of any Dynamics AX project, system configuration is adjusted depending on the testing results. This process may be performed as many times as required until the system is ready. During this process, it might appear that at some point the system have too many transactions, which may impact further tests. If this happens, then the data is wiped out by exporting configuration data, deleting whole company, and importing configuration data back. Data clean-up is also required when "fresh" retesting is required.
Although the described process does the job, it might be slightly time consuming. During my developments, I found the undocumented class called SysDatabaseTransDelete in the standard Dynamics AX application. Once started, it deletes all transactional data in the current company. It allows us to quickly get rid of all transactions and leaves configuration data intact.
But although this class is useful during the testing stages, it definitely should not be used in production environments.
In this recipe, we will explore how to delete all transactional data using the mentioned application class.
First, we need to make a copy of an existing company account to make sure we are not deleting the data in the current company. Open Administration | Company accounts, and select the current company:
Click on the Duplicate button, and then type in the details for a new company:
After a couple of moments, a new company should be created. Select it in the form and click on the Select button to make sure you start working in it:
Next open AOT, find the SysDatabaseTransDelete class in AOT, and run it.
Click Yes to acknowledge that you want to delete all transactions:
In this recipe, we use the SysDatabaseTransDelete class, which is included in the standard Dynamics AX application. No additional coding is required. We simply need to run it in the company that we want to clean up. This class is not included in any menu, so it has to be started from AOT. The class deletes all data in the current company account from all tables belonging to the Transaction, WorksheetHeader, and WorksheetLine table groups.