Friday, 4 December 2015

Dynamics Ax 2012 : Exploring the Cross company Queries in dynamics Ax 2012

Static AOT Query:
You can set Allow cross company true By properties of AOT Query .

Cross Company

X++ Query object:
One way to create query in dynamics Ax is Query object. You can add by following way.

Query query;

QueryRun queryRun;

QueryBuildRange queryBuildRange;

QueryBuildDataSource queryBuildDataSource;

query = new Query();

queryBuildDataSource = query.addDataSource(TableNum(CustTable));


//Executes query built so far

queryRun = new QueryRun(query);

This is most fastest way to get cross company data.

While select Query:

There two ways for Get cross Company query and or Query inside the change company statement.
Cross company Keyword:
Add cross company query inside the while select statement to extract data all legal entities in Dynamics AX as  follow code.
Custtable _CustTable;

While select crosscompany * from _Custtable


Info (_Custtable.AccountNum + “   :  “ + int642str(_Custtable.DataAreaId);


If you want to restrict the query to fetch data from limited legal Entities you have to use a container as follow.

Container _ListOfLegalEntites ={ ‘mazang’,’Jubergi’,’Urdu Bazar’};

While select  crosscompany:_ListOfLegalEntites * from _Cust


Info(_Custtable.AccountNum + “  :  “ + _Custtable.DataAreaId);


Change Company Keyword:

One method is to use change company keyword. It is most time consuming method. To reduce its time, we have rest the table to null when Change Company happened. In Dynamics All legal entities name stored at  DataArea table we use this table to get the list of datarea and used inside the changeCompany  query on it as follow.
DataArea _DataArea;

Custtable _Custtable;

While select Id from _DataArea



_Custtable= null;

While select * from _Custtable


Info(_Custtable.AccountNum +”  :   “ + _Custtable.AreaId);



No comments:

Post a Comment