Hi Everyone today i would like share information regarding how to retrieve data from Selected companies or from a specified company by using Keywords known as CrossCompany and ChangeCompany in Dynamics Ax, with a simple example.
CrossCompany : By using this keyword we can retrieve data from multiple selected companies or from all companies.
CrossCompany : By using this keyword we can retrieve data from multiple selected companies or from all companies.
Example:- We'll be using the well known demo data table (i.e, CustTable).
CustTable custTable;
Container con;
Container con;
// Assigning the required Companies to the container
con = ["CEU","DAT","CEE"];
// CrossCompany:Object is the syntax for using CrossCompany keyword
Select crosscompany:con custTable;
info( strfmt("%1",custTable.accountnum));
info( strfmt("%1",custTable.accountnum));
ChangeCompany : By using this keyword we can change company any time and retrieve data from specific companies.
For Easy Understanding: Let say i'm in the CEU Company and i would like to get the data belonging to the CEE Company. Then i would Prefer to Use ChangeCompany Keyword.
Example:-
CustTable custTable;
CustTable custTable;
Select * from custTable;
info( strfmt("%1",custTable.accountnum));
info( strfmt("%1",custTable.accountnum));
//Accessing the data from a specified company by using the ChangeCompany Keyword
// changecompany("Company Name") is the Syntax for ChangeCompany Keyword.
changecompany("CEE")
{
custTable = null
Select * from custTable;
info( strfmt("%1",custTable.accountnum));
}
changecompany("CEE")
{
custTable = null
Select * from custTable;
info( strfmt("%1",custTable.accountnum));
}
// Retrieving from another selected Company
changecompany("CEEU")
{
custTable = null
Select * from custTable;
info( strfmt("%1",custTable.accountnum));
}
changecompany("CEEU")
{
custTable = null
Select * from custTable;
info( strfmt("%1",custTable.accountnum));
}
Proud To Be a DAX Developer :-)