Miklix

Delete a Legal Entity (Company Accounts) in Dynamics AX 2012

Published: February 26, 2021 at 5:15:12 PM UTC

In this article, I explain the correct procedure for completely deleting a data area / company accounts / legal entity in Dynamics AX 2012. Use at your own risk.


The information in this post is based on Dynamics AX 2012 R3. It may or may not be valid for other versions.

Notice: There is a very real risk of data loss if you follow the instructions in this post. In fact, it is exactly about deleting data. You should generally not delete legal entities in production environments, only in test or development environments. Usage of this information is at your own risk.

I was recently tasked with completely removing a legal entity (also known as company accounts or data area) from a Dynamics AX 2012 environment. The reason the user didn't just do it herself from the Legal entities form was that it spewed out some ugly errors about not being able to delete records in certain tables.

After looking into it, I discovered that you cannot delete a legal entity that has transactions. That makes sense, so the obvious solution would be to remove the transactions first, and then delete the legal entity.

Fortunately, Dynamics AX provides a class for removing the transactions of a legal entity, so this is fairly straightforward - although, quite time consuming if you have a lot of data.

The procedure is:

  • Open the AOT and find the class SysDatabaseTransDelete (in some earlier versions of AX it was just called "DatabaseTransDelete").
  • Make absolutely sure you\'re currently in the company for which you want to delete the transactions!
  • Run the class found in step 1. It will prompt you to confirm that you wish to remove the transactions. Again, make absolutely sure that the company it asks about is the one for which you want to delete the transactions!
  • Let the task run. This can take quite a while if you have many transactions.
  • Once it\'s done, return to the Organization administration / Setup / Organization / Legal entities form. Make sure you're not in the company you want to delete at this point, as you can't delete the current company.
  • Select the company you want to delete and press the "Delete" button (or Alt+F9).
  • Confirm that you want to delete the company. This will also take a while, as it's now deleting all the non-transactional data in the company.
  • Sit back, relax and revel in the glory of a job well done! :-)
Share on BlueskyShare on FacebookShare on LinkedInShare on TumblrShare on XShare on LinkedInPin on Pinterest

Mikkel Bang Christensen

About the Author

Mikkel Bang Christensen
Mikkel is the creator and owner of miklix.com. He has over 20 years experience as a professional computer programmer/software developer and is currently employed full-time for a large European IT corporation. When not blogging, he spends his spare time on a vast array of interests, hobbies, and activities, which may to some extent be reflected in the variety of topics covered on this website.