Skip to main content

Posts

Showing posts with the label cross company

Cross Company Query

Sometimes we need to fetch data from several companies. Straight forward way is to use a crossCompany keyword in a select statement: container conCompanies = ['cee', 'cec', 'ceu']; while select crossCompany : conCompanies * from CustTable { ... } More elegant and flexible method to select cross company would be to use a query with a parameter AllowCrossCompany set to Yes. This parameter enables additional tab in a query selection dialog which allows user to select companies. In the same manner cross-company fetch of data can be done in X++: static void crossCompanyQuery(Args _args) { Query q = new Query(); QueryBuildDataSource qbds; QueryRun qr; CustTable ct; Container con; ; qbds = q.addDataSource(tableNum(CustTable)); qbds.addSortField(fieldNum(CustTable, dataAreaId)); // by default adds all companies to which current user has access rights q.allowCrossCompany(NoYes::Yes); //q.addCom...

crosscompany

Metod 1; container conCompanies; while select dataArea where !dataArea.isVirtual { conCompanies += [dataArea.id]; } while select crosscompany : conCompanies inventTable { // ... do something ... } metod 2; public Query buildQuery() { Query query = new Query(); QueryBuildDataSource qbds; DataArea dataArea; ; query.allowCrossCompany(true); while select dataArea where !dataArea.isVirtual { query.addCompanyRange(dataArea.id); } qbds = query.addDataSource(tablenum(InventTable)); qbds.addRange(fieldnum(InventTable, ItemId)); qbds.addRange(fieldnum(InventTable, PrimaryVendorId)); return query; } metod 3; DataArea dataArea; ; while select dataArea where !dataArea.isVirtual { changeCompany(dataArea.id) { // ... do something ... } }

Cross Company - Part 1

First of all, let’s describe the default behavior the AX kernel takes when a cross company query is issued. Here is an example of a cross company query: static void CrossCompanyTest(Args _args) { Address address; container conCompanies = [ 'a0', 'a1', 'dat' ]; ; while select crossCompany :conCompanies address order by dataAreaId return; } Cross company queries in Dynamics AX 2009 will include an IN list of DATAAREAIDs: SELECT … FROM ADDRESS A WHERE A.DATAAREAID IN (?,?,?) ORDER BY A.DATAAREAID