changeCompany Vs crossCompany

changeCompany  : The changeCompany statement is used to alter the database settings to another (separate) company.

crossCompany : crossCompany statement is used to  get data from all the companies.

Microsoft Dynamics AX can have multiple companies in one data base. It is a common requirement to retrieve data from many or all of these companies in a function. This can be achieved in one select statement by using the crossCompany keyword. If just the keyword is used, it will search all companies. You can also specify a container that defines which companies to search.

static void CrossCmpyVsChangeCmpy(Args _args)
{
CustTable custTable;

// Below will get the data from Current Company
info("Data from current company");
while select * from custTable
info(strFmt("%1-%2",custTable.AccountNum,custTable.dataAreaId));

// Below will get the data from the specified Company
changecompany('ussi')
{
custTable = null;
info("Data from USSI company");
while select custTable
info(strFmt("%1-%2",custTable.AccountNum,custTable.dataAreaId));
}

// Below will get the data from all the Companies
info("Data from all companies");
while select crossCompany * from custTable
info(strFmt("%1-%2",custTable.AccountNum,custTable.dataAreaId));
} 

or

container conCompanies = [ 'cee', 'ceu' ];
custTable custTable;
while select crossCompany : conCompanies custTable
{
print custTable.accountNum;
}
pause;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s