crossCompany and changeCompany in AX 2012
Hi Folks,
Today, in this article we will understand the use of crossCompany and changeCompany in AX 2012.
Let's start...
crossCompany:
You can fetch the data from tables across companies using crossCompany keyword in X++ select queries. Suppose you have a requirement to get the data from multiple companies in AX 2012 using X++ then in this scenario we can use crossCompany.
You can also use containers to fetch data from subset of companies.
For example:
changeCompany:
You can use changeCompany function in X++ to change companies. Suppose you are login with Company 'A' and you want to fetch the data for company 'B'. In this scenario we can use changeCompany.
For example:
Author:
Chirag Gupta
Microsoft Dynamics D365/AX 2012
Senior Technical Consultant at IBM Bangalore
Date:
4-Apr-2020
Happy Learning !!
Today, in this article we will understand the use of crossCompany and changeCompany in AX 2012.
Let's start...
crossCompany:
You can fetch the data from tables across companies using crossCompany keyword in X++ select queries. Suppose you have a requirement to get the data from multiple companies in AX 2012 using X++ then in this scenario we can use crossCompany.
You can also use containers to fetch data from subset of companies.
For example:
public void TestCrossCompanyUse()
{
CustTable custTable;
container desiredCompanies = ['A', 'B']; // A and B are companies name
int iCountCompanies = 0;
while select crossCompany : desiredCompanies * from custTable
{
info(strFmt("%1, %2", custTable.AccountNum, custTable.dataAreaId));
iCountCompanies++;
if (iCountCompanies >= 1000 )
{
break;
}
}
}
Note: In X++ code you can use the Query .allowCrossCompany property method to achieve the same result as you can with the crossCompany keyword on a select statement. The calls to the Query .addCompanyRange method are the same as appending a container of companies to the crossCompany keyword.{
CustTable custTable;
container desiredCompanies = ['A', 'B']; // A and B are companies name
int iCountCompanies = 0;
while select crossCompany : desiredCompanies * from custTable
{
info(strFmt("%1, %2", custTable.AccountNum, custTable.dataAreaId));
iCountCompanies++;
if (iCountCompanies >= 1000 )
{
break;
}
}
}
changeCompany:
You can use changeCompany function in X++ to change companies. Suppose you are login with Company 'A' and you want to fetch the data for company 'B'. In this scenario we can use changeCompany.
For example:
static void TestChangeCompanyUse(Args _args)
{
CustTable custTable;
// We are login with company 'A' and want to fetch the data for company 'B'
changeCompany('B')
{
custTable = null; // To clear the old memory
while select * from custTable
{
info(strFmt("%1, %2", custTable.AccountNum, custTable.dataAreaId));
}
}
}
We hope this article helped you to understand the use of crossCompany and changeCompany using X++ in AX 2012. Please comment your valuable feedback for this article...{
CustTable custTable;
// We are login with company 'A' and want to fetch the data for company 'B'
changeCompany('B')
{
custTable = null; // To clear the old memory
while select * from custTable
{
info(strFmt("%1, %2", custTable.AccountNum, custTable.dataAreaId));
}
}
}
Author:
Chirag Gupta
Microsoft Dynamics D365/AX 2012
Senior Technical Consultant at IBM Bangalore
Date:
4-Apr-2020
Happy Learning !!
Comments
Post a Comment