---
title: "Working with Intercompany functionality"
canonical: https://ontargit.com/working-with-intercompany-functionality/
date: 2021-06-23 11:33:05
description: "Working with Intercompany functionality in Microsoft Dynamics AX to fetch data from all companies at once, not just from the current company."
keywords: "Intercompany functionality"
categories: [Tech article, CRM, ERP]
---

## Version of Microsoft Dynamics AX: D365O

### 1. Selects

- __

1.1 Fetching data from all companies with crosscompany

Using intercompany functionality to fetch data from all companies at once, not just from the current company, as in the case with a regular **select**, use keyword **crosscompany**.

_

- _

1.2 Fetching data from multiple companies with crosscompany

To **select** data not from all companies at once, but only from some of them, use keyword **crosscompany** and specified a list of companies:

- __

option, where the list of companies is set in the container

_

- _

option, where the list of companies is set in the **where** section

_

- _

1.3 Fetching data from one specified company with crosscompany

Another way to fetch data from a company other than the current company is to “switch” to another company using changecompany. In this case, all the code is executing in the context of the specified company.

_

## Enhance your project delivery with OntargIT partner services

We are not a recruitment organization that just hires and resell resources. Instead we are [**service-oriented partner** ](https://ontargit.com/en/partner-services-oit/)focusing on long term collaboration with customers and development of our teams. We obtain expertise which we’ve got by providing implementation consulting  to end customers for many years, and great team synergy we’ve built by doing so.

[Free consultation_](https://ontargit.com/en/ontargit-contacts/)

### 2. Forms data sources

- __

2.1 Displaying data from multiple companies

If you need to fetch data from multiple companies at the same time in the form data source, you need to change the value of property **Cross Company Auto Query** to «Yes». In this case, the data will be selecting from all existing companies.

_

To limit the list of companies, you need it set the values of the required companies in the init() method of this data source.

### 3. Copying records

- _

3.1 Copying using buf2buf function

To copy a record from one company to another, you need to “switch” to the desired company using **changecompany** and initialize all the fields (except system fields) of the new record with _buf2buf_ function.

Below is the code for a method that creates a new record and initializes its fields with the values of the original record:

_

As an example of the standard buf2buf function using you can see the class CustFreeInvoiceCorrection.

- _

3.2 Copying using a table _data_ method and then adjusting the system fields

In cases where, for some reason, you to save the values of the system fields of the original record, except for field **DataAreaId**, since this field must in any case correspond to the company in which the new record is created, use the table data method.

At the same time, when creating a new record, some of the system fields can be overridden, and field **DataAreaId** must be overridden.

Overriding system fields must be allowed by special construction with using OverwriteSystemfieldsPermission().assert() и overwriteSystemfields().

Here is an example of code that overrides system fields in the new record.

### 4. Intercompany Sales Purchase orders

An example of the standard Intercompany functionality is association between purchase order in one company and sales order in another company.

Having a purchase order, you can get an intercompany sales order and having a sales order, you can get an intercompany purchase order.

Below are custom examples of receiving sales and purchase orders.

Here is an example of standard code in MarkupCopy class that gets intercompany sales order..