Crosscompany Property is not working

887 views Asked by At

I have a cross-company property ("Yes") enabled query.,even though query returns values for the current company in Dynamics 365 (AX7)

I even tried with changecompany() but there is no data for any other companies apart from current company.

_query.allowCrossCompany(true);
 qr=new QueryRun(_query);
while(qr.next()) 
{ 
companyInfo =qr.get(tableNum(CompanyInfo));
info(strfmt("%1",companyInfo .DataArea));
} 

here query is cross company query but still it showing the values for current company only(ie, if I run this code from USA dataarea shows only USA not other companies)

1

There are 1 answers

2
Alex Kwitny On

First, CompanyInfo is SaveDataPerCompany = No, so cross company serves no purpose.

Second, you must not be providing all of your code, because I just created/tried both of these jobs and they worked fine for crossCompany. Job12 is the one similar to what you did, but it still works.

static void Job11(Args _args)
{
    Query           query   = new Query();
    QueryRun        qr;
    SalesTable      salesTable;

    query.addDataSource(tableNum(SalesTable));
    query.allowCrossCompany(true);

    qr      = new QueryRun(query);

    while(qr.next()) 
    {
        salesTable = qr.get(tableNum(salesTable));
        info(strFmt("%1 %2", salesTable.SalesId, salesTable.dataAreaId));
    } 
}


static void Job12(Args _args)
{
    Query           query   = new Query();
    QueryRun        qr;
    CompanyInfo     companyInfo;

    query.addDataSource(tableNum(CompanyInfo));
    query.allowCrossCompany(true);

    qr      = new QueryRun(query);

    while(qr.next()) 
    {
        companyInfo = qr.get(tableNum(CompanyInfo));
        info(strfmt("%1", companyInfo.DataArea));
    } 
}