web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Do mapping on export using standard data entity

(1) ShareShare
ReportReport
Posted on by 18
Hi
 
It'm trying to do some data mapping when exporting Customer data using CustCustomerV3Entity
 
The goal is to 'replace' tax group on some of the customers when exporting the data an I have created this extension class;
 
 
 
 

/// <summary>

/// Extenion of CustCustomerV3Entity to do mapping on export

/// </summary>

[ExtensionOf(dataentityviewstr(CustCustomerV3Entity))]

final class CustCustomerV3Entity_datamig_Extension

{

    public void mapDataSourceToEntity(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)

    {

        next mapDataSourceToEntity(_entityCtx, _dataSourceCtx);

        if (_dataSourceCtx.name() == dataEntityDataSourceStr(CustCustomerV3Entity, CustTable))

        {

            CustTable custTable = _dataSourceCtx.getBuffer();

            container fromSalesTaxGroup = ['group_1','group_2','group_3'];

            container toSalesTaxGroup = ['new_group_1','new_group_2','new_group_3'];

            int fromSalesTaxGroupPos;

            fromSalesTaxGroupPos = conFind(fromSalesTaxGroup,custTable.TaxGroup);

            if(fromSalesTaxGroupPos)

            {

                this.SalesTaxGroup = conPeek(toSalesTaxGroup, fromSalesTaxGroupPos);

           }

        }

    }

}

 
 
But during export the method is not called is extensions not allowed or did i miss something ?
 
Thanks
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    239,449 Most Valuable Professional on at
    This indeed isn't a viable approach. Instead, use a virtual field or a computed column.
  • CU03040925-0 Profile Picture
    18 on at
    @Martin Dráb What is the problem and how would a computed field solve the task ?

    The point is to be able to import the data in another instance of D365, without to do customization in the new instance.
     
  • Suggested answer
    Martin Dráb Profile Picture
    239,449 Most Valuable Professional on at
    The problem is that you can't do that in mapDataSourceToEntity(). To calculate a value in code, you need to use one of the way I mentioned.
     
    The default approach of a data entity is just exporting the data from the backing SQL view. With a computed column, you can add a calculated value to the view. With a virtual field, you can actually run a piece of X++ code for each record (which is much slower). 
     
    If your goal is transforming the data exported from one instance before importing to another one, you have other options to consider as well. For example, you could use Conversion in the mapping of the import project. Or you could export the file without any transformation, replace the value in the file and import the modified file.
  • CU03040925-0 Profile Picture
    18 on at
    Thanks for your explanation and I think that I have to use the conversion functionality
     
     
    Just as side note: Have a look at this standard code: this is 'basically' what I wanted to do, and the comment even say that it's for exporting

     /// <summary>

     /// Converts TableId to TableName for data entity export.

     /// </summary>

     /// <param name = "_entityCtx">Data entity context.</param>

     /// <param name = "_dataSourceCtx">Data source context.</param>

     public void mapDataSourceToEntity(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)

     {

         super(_entityCtx, _dataSourceCtx);

         if (_dataSourceCtx.name() == "EInvoicePropertyTypeApplicabilitySetup")

         {

             EInvoicePropertyTypeApplicabilitySetup dsAppl = _dataSourceCtx.getBuffer();

             this.TableName = tableId2Name(dsAppl.RefTableId);

         }

     }



     
  • Martin Dráb Profile Picture
    239,449 Most Valuable Professional on at
    I guess you're talking about EInvoicePropertyTypeApplicabilitySetupEntity. TableName isn't a regular field; it's an example of a virtual field (as discussed below). There is code populating the value in postLoad() and mapDataSourceToEntity(), but I don't think that the copy in mapDataSourceToEntity() has any effect.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 586 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 551

#3
CP04-islander Profile Picture

CP04-islander 408

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans