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"
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 = null;
select count(RecId) from custTable;
info (strFmt(" Company: %1, # of Customers: %2"