D365 FO/AX7: Cross-company & Change-company for accessing Data for Multiple Companies Using X++

Introduction

In Microsoft Dynamics AX/D365 Finance and operation, users can setup multiple legal entities. By default in Microsoft Dynamics AX/D365 FO, all tables store data per company unless SaveDataPerCompany  property is not changed to NO. By dafault value of property SaveDataPerCompany  = Yes.Using crosscompany & changecompany keyword, you can construct a query to retrieve all records, regardless of the company you are currently logged into.You can fetch the all the company records using keyword -crosscompany and function – changecompany.

Change-Company

static void main()
{
  CustTable custTable;
  changeCompany('INMF') 
  {
    custTable = null;
    while select custTable
    {
       //custTable of company 'INMF'.
    }
  }
}

Cross-Company

static void main()
{
  CustTable custTable;
  while select crosscompany custTable
  {
      custTable of all the companies
  }
}

Leave a Reply