How to use CrossCompany & changeCompany in Ax 2012

CrossCompany & changeCompany

CrossCompany:

You can fetch data from tables across companies using CrossCompany keyword in X++ select queries.

You can also use containers to fetch data from subset of companies.

For example,

While Select * from InventTable CrossCompany: [DAT, TEST]

{

<<Do Something here>>

}

You can also use AllowCrossCompany Property to Yes on  Queries to fetch data from across companies

changeCompany functions:

changeCompany:

You can use changeCompany function in X++ to change companies and fetch data from wherever you want

Example:

static void main()
{
CustTable custTable;
;

//Assume that you are running in company ‘aaa’.
changeCompany(‘bbb’) //Default company is now ‘bbb’.
{
custTable = null;
while select custTable
{
//custTable is now selected in company ‘bbb’.
}
}

//Default company is again set back to ‘aaa’.

changeCompany(‘ccc’) //Default company is now ‘ccc’.
{
//Clear custTable to let the select work
//on the new default company.
custTable = null;

while select custTable
{
//custTable is now selected in company ‘ccc’.
}
}

//Default company is again ‘aaa’.
}

Make table buffer to null before using it as the DataAreaID of the buffer still points out to old company – The changeCompany does not do this automatically

changeCompany (‘B’)
{
inventItemGroup = null;
inventItemGroup.ItemGroupId = ‘IB’;
inventItemGroup.insert();
}

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