Friday, March 4, 2016

Export Sales orders in 5 easy steps in new Microsoft Dynamics AX RTW

In my last post, I have mentioned how to use OOB composite entity for Import/Export using Data management. In this post I will show, how to create your own composite entity. I am taking the example of Sales Order which includes Sales Header and Sales Line.

Step 1: Go to visual studio and create your custom model for Application Suite model.

Step 2: Customize the table SalesOrderHeaderStaging.

Create 2 new fields in table: RowId and ParentRowId. To create these fields, you can drag drop fields from BankJournalHeaderStaging, Similarly Create index RowIdx

Step 3: Customize the table SalesOrderLineStaging.

Create 2 new fields in table: RowId and ParentRowId. To create these fields, you can drag drop fields from BankJournalHeaderStaging, Similarly Create index RowIdx. Create a relation to SalesOrderHeaderStaing Table as shown below in the screenshot.

Step 4: Create new composite entity. Give it a name SalesOrderDataEntity. Add new root data entity reference: SalesOrderHeaderEntity and then New Embedded Data Entity Reference: SalesOrderLineEntity

Make sure Relation is set to SalesOrderHeader.

Step 5: Build the solution. Create the Export data entity as shown in below snapshot. 

Click on the Export and that's it. You can now download the file which looks like below:


  1. I hope it's also possible to create the same by using extensions instead of overlayering...

    1. I tried that with the Extension first, but that didn't work so I had to do customization. Other thing is to create new custom data entities for Sales header/sales line and then use them for composite entity

  2. Hey there,

    Thanks for all the info. I've now learned that I need to add a relation on the Staging table level too.

    We've run into another issue with the data entities in AX7. I have created a composite entity with the entities for SalesAgreementHeader and AgreementLines, but whenever I try to do an export I get an error.

    When I take a look at the staging data I see that the header table has gotten all the records inserted correctly, but on the lines I only have one record (even though it says 11 records exported), and I have this error log:

    System.Exception: Object reference not set to an instance of an object.
    at Microsoft.Dynamics.AX.Framework.Tools.DMF.ServiceProxy.DmfEntityProxy.DoWork[T](Func`1 work)

    No one of us on this project can figure out what goes wrong. Do you have any idea?

    1. Hi Sascha,

      Thank you for reading. I have few suggestions, you can try.
      1. Try creating export processing groups for Header and Line separately and see if export works independently.
      2. See if you can debug it. check post
      3. I tried to create data entities quickly to check but while creating data entity for AgreementLine table, I was getting error " The natural key for the table AgreementLine was not found". I will try to find out the solution. I wanted to check if you faced the same issue as well?

  3. Thanks for the reply.
    I have tried creating an export processing group for the header and line separately, and both work good. By the way, we noticed that the only out-of-the-box composite entity that works in AX is the CustomerPaymentJournal. And we'll try debugging tomorrow.

    As for the natural key error, we have a workaround.
    1. Create a Data Entity with a valid table as a datasource (I use AccountingGroup).
    2. Then create a view with AgreementLine as a datasource, and then add SalesAgreementHeader below it (no relations needed!) and then add a unique field, in our case you can use the SalesNumberSequence, to the view.
    3. After that you should manually be able to add this View as a data source for the data entity (and update the staging table too).

    I'll update with any further progress in this issue.

  4. RowIdx index property allowduplicates must be set to YES. Otherwise composite entity not working as RowId and ParentRowId is 0 for all the records. Not sure why these fileds are not getting updated and when these will be updated? may be a bug? Bydeafult index allowduplicate is set to NO, then getting error while exporting data. Hope this will help.