Thursday, 23 March 2023

Changing Company Id in D365 FO

 Changing the company id in D365 FO is not directly possible and also not a recommended approach. But there still is a way through which we can change the Id in rare cases. Below are the list of technical steps to be followed for changing the company id (DataAreaId).

Note: Please take the database back up before any changes to revert back in case of any issues during the process.

There are three scenarios of tables where the company Id is present.  They all need to be updated in order to bring the new Id all over the application.

1. Company Specific tables where there is a DataAreaId filed available.
  • Use the below stored procedure command in SQL to update the field in all tables with the values required.
  • Use the below SQL query to update the table "DataArea"
  • Get the list of tables using the below query

        EXEC sp_MSforeachtable 'update ? set DataAreaID = "XNEW" where ?.DataAreaID = "XOLD"

2. DataArea Table
        UPDATE DataArea SET ID = 'XNEW' WHERE DataArea.ID = 'XOLD'

3. Global tables which do not have a default framework maintained "DataAreaId" field but has a physical ordinary field called "DataArea".

  • Use the below SQL query to get the list of table having the field as DataArea

        SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES 
            WHERE TABLE_TYPE = 'BASE TABLE' 
            AND TABLE_NAME NOT IN (SELECT DISTINCT TABLE_NAME    
            FROM INFORMATION_SCHEMA.COLUMNS 
            WHERE COLUMN_NAME = 'DataArea');
  • Update the list of tables with the new companyId value in the fields.
        UPDATE TableName SET DataArea = 'XNEW' WHERE DataArea.ID = 'XOLD'



No comments:

Post a Comment