Skip to main content

Delete an AX company on SQL

This week, we were shrinking a database of a development environment by deleting some companies.
Here a nice little SQL statement that uses the sp_MSforeachtable stored procedure to delete all records of a specific company (CEU in this case) from all tables.
EXEC sp_MSforeachtable 'delete from ? where ?.DataAreaID = "CEU"'
Certainly fast(er than AX) and gets the job done.
Use at your own risk ;-)
Update:
You’ll want do do some cleaning up to:
delete the company id from the DataArea table and from the CompanyDomainList table
DELETE FROM DataArea WHERE DataArea.ID = 'CEU'
DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID = 'CEU'
Update 2:
When you want to delete all companies execpt a few (like DAT), just use this:
EXEC sp_MSforeachtable 'delete from ? where ?.DataAreaID <> "DAT" AND ?.DataAreaID <> "DEMO"'
DELETE FROM DataArea WHERE DataArea.ID <> 'DAT' AND DataArea.ID <> 'DEMO'
DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID <> 'DAT' AND CompanyDomainList.CompanyID <> 'DEMO'
This will delete all companies except DAT en DEMO.

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }