Dynamics AX – Accessing Data for Multiple Companies

Have you ever had to compare data for several companies in Microsoft Dynamics AX?

That is usually not a problem to change the company you are currently attached to. You just double-click the company on the bottom of your current work space, and change it.

 

 

 

This becomes more of a challenge when dealing with more than a handful of companies.

That is where the crossCompany and changeCompany keywords can be helpful.

The table DataArea stores the company Id for all companies configured in your environment. Using the crossCompany keyword, you can construct a query to retrieve all records, regardless of the company you are currently logged into. This example loops through all of the companies in the table DataArea, then calls a routine to do some work in that company.

while select crossCompany * from dataArea

{

info (strFmt(“%1 %2”

, dataArea.Id

, dataArea.name

));

showCompany(dataArea.Id);

}

In this example, I just want to know how many customer records exist in each company. This routine will use the changeCompany keyword to define the scope of work. Using this, I can run one job to interrogate all companies that are set up, or you can manually change companies and run the query in each company. You decide which is more efficient.

void showCompany(DataAreaId _dataAreaId)

{

CustTable   custTable;

;

changeCompany(_dataAreaId)

{

custTable = null;

select count(RecId) from custTable;

info (strFmt(”  Company: %1, # of Customers: %2″

, _dataAreaId

, custTable.RecId

));

}

return;

}

To learn more about how Tridea Partners can help you get the most out of your Microsoft Dynamics AX solution, visit www.trideapartners.com or contact us at info@trideapartners.com.