Introduction

In Dynamics 365 Finance and Operations (F&O), a data entity’s company scope is defined by its primary data source by default. So, when the data entity is for a company-specific table, it is company specific, and when the data entity for a non-company specific table, the opposite is true.
This behaviour can be changed, so that an entity for company-specific table(s) can support multiple legal-entities, which would allow CDS-DI to move data between single CE business unit and multiple F&O legal entities in a single project.
In this post, I will highlight the required changes on F&O side first and then discuss few options on the integration side. There are 3 main steps: 1) Change the export behaviour, 2) Change the import behaviour and 3) Implement legal-entity scope in CDS-DI.

Scenario

Extend Prospect to cash: Accounts / Customers integration so that accounts from CE can flow into multiple F&O legal entities.

Prerequisite

Duplicate CustCustomerV2 entity into your own entity. E.g. CustCustomerV2EntityMultiLE.

  1. Duplicate the standard entity CustCustomerV2Entity into CustCustomerV2EntityMultiLE 

  2. Change few properties to avoid any naming conflicts with the standard entity, then regenerate staging table.

    Properties to change are: Label, Data management staging table, public collection name & public entity name 

      

      

  3. Create required security privileges by duplicating the standard ones and point new ones to your entity

      

  4. At the end, this is how your project should look like

      

Change the export behaviour

For this you need to change the Primary company context property to none. Since this can’t be done on existing entities via extension, you can either duplicate the entity or nest it inside a new one. In this post we will use the duplicate entity from previous steps.

  1. Set Primary company context property to blank

  2. Add a new field, mapped to the record’s company. Let’s call it CustomerDataAreaId

  3. Add the same field to the entity keys and update staging table

      

  4. With that, the entity is ready and can be tested with a file-based export project.

    Here is the test results from a file-based export 

Change the import behaviour

Wrap the super() call of insert, update, delete and validateWrite methods  with a change company construct. 

    /// <summary>
    ///
    /// </summary>
    public void delete()
    {
        changecompany(this.CustomerDataAreaId)
        {
            super();
        }
    }

    /// <summary>
    ///
    /// </summary>
    public void update()
    {
        changecompany(this.CustomerDataAreaId)
        {
            super();
        }
    }

    /// <summary>
    ///
    /// </summary>
    public void insert()
    {
        changecompany(this.CustomerDataAreaId)
        {
            super();
        }
    }

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public boolean validateWrite()
    {
        boolean ret;
    
        changecompany(this.CustomerDataAreaId)
        {
            ret = super();
        }
    
        return ret;
    }

Implement legal-entity scope in CDS-DI

Last thing is to determine which legal entities a customer’s record should be imported to, by mapping the new CustomerDataAreaId field into a value. Such value could be passed from CE, if it’s stored there, or can even be added in the integration project based on some logic.

For demonstration purposes, we’ll add a static list of legal entities to the data through PowerQuery, so that accounts would be imported into 2 legal entities.

Note: Below screenshots are from the new data integration user interface. so you might get a slightly different experience if you're still using the old UI.

  1. Create a new project from the standard Accounts integration template

  2. Add a new task, with the Target selection of the previously created entity (Customers V2 – Multi LE)

  3. Repeat the same field mapping between accounts and customers. Use the first task as reference.

  4. Now you can delete the first task, leaving only the new task in your project

  5. Enable advance query so we can enrich the data with legal entity values

  6. Go to task details and click on Advanced query and filtering

  7. Since we’re using a static list of legal entities, Let’s get data from a Blank table

  8. Update the table name, column name and add two records for USMF and USP2 as shown below

  9. Go back to CE data (QrySourceData) and click on Merge queries under Combine tables


  10. Select the Legal entities table with a full outer join

  11. Expand the legal entities joined table by clicking on the expand icon and click ok.

  12. By now the data is ready and each account has 2 legal entity values. You can save your query and go back to your project

  13. Refresh available fields by going to the project and back into the mapping

  14. Map the new fields as shown below, save the project and you’re ready to go

  15. Do a final test by running the project and notice how data flows into multiple legal entities