Skip to main content

Cross company reports [AllowCrossCompany] in Dynamics AX , X++

This report example will help you to get the data from selected companies or all companies using AllowCrossCompany property
In the AOT, query node objects have the AllowCrossCompany property listed in the Properties window. For new queries the default value is No (which is equivalent to false in X++ code). To make a query cross-company you need to set AllowCrossCompany to Yes.
The classes QueryRun and Query both have the AllowCrossCompany property, but their values always equal each other. When you read AllowCrossCompany from QueryRun, QueryRun reads it from Query. When you set AllowCrossCompany on QueryRun, it sets in on Query.
Please follow me to get the report from multiple companies as shown below.
Right click on AOT >> Reports and Create a new report by name “SR_CrossCompanyItems” as shown below

Expand the datasources and add InventTable as datasource.
On the Query Node, right click and go to property and set the AllowCrossCompany peroperty to “Yes” as shown below.

Expand the design and add Body control to it . Add three fields [ItemId, ItemName and DataAreaId] from the InventTable datasources [Drag- Drop] as shown below

Right click on the report and open the report
Select the print medium as screen and below is the output

If you want to restrict the report to only selected companies data , override the report init() method and add the following code in the init() method

public void init()
{
super();
this.query().allowCrossCompany(true);
this.query().addCompanyRange(“dat”);
this.query().addCompanyRange(“ceu”);
}

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }