AX 7. Process the data after Data Entity import.

It’s a common requirement to perform post actions on records that are imported by Data Entity, for example to invoice created sales order or to post created journal.

To do this we need to add a new method postTargetProcess() to our Data Entity. This method is automatically called by the DMFEntityWriter class in the end of processRecords() method when all records are transferred from staging to target. It is not available from override method drop down on Data Entity because it is static and is called via reflection.

/// <summary
/// Executes the logic once after processing the target data.
/// </summary>
/// <param name= “_dmfDefinitionGroupExecution">
/// The definition group that should be processed.
/// </param>
public static void postTargetProcess(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
    //check if import job is finished
    if (_dmfDefinitionGroupExecution.StagingStatus == DMFBatchJobStatus::Finished)
        MyStaging myStaging;

        //select all staging records that were processed by current execution job without errors.
        while select myStaging
            where myStaging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup
               && myStaging.ExecutionId     == _dmfDefinitionGroupExecution.ExecutionId
               && myStaging.TransferStatus  == DMFTransferStatus::Completed
            //here you can find newly created records and update\post them.

Please note that it can be done only in data management scenarios but not via OData because OData updates\inserts records row by row and there is no post event\method to use.

18 thoughts on “AX 7. Process the data after Data Entity import.

  1. Shinji November 4, 2016 / 5:44 am

    how to process the data before Data Entity export?

    • ievgensaxblog November 4, 2016 / 6:55 am

      Hi Shinji,
      What are you actually doing ? Do you want to add some logic before writing to staging table ? Do you use staging table at all ?

  2. Karolis March 25, 2017 / 8:01 am


    if I would like to populate target from staging in two different cases:
    1. passing ServiceOrderId (would not allow, as field on target is set block modification on insert);
    2. generating ServiceOrderId in the code if possible when populating data from staging to target.

    Would you be able to advice how to achieve listed above?

    Thank you in advance!


    • Ievgen Miroshnikov March 25, 2017 / 8:28 am

      Hi Karolis,
      Is it a standard entity ?
      Do you want to use number seq or pass values from a file ?
      Why you don’t want to have values in staging and want generate them only on insert to target?

      • Karolis March 25, 2017 / 9:42 am


        That’s custom data entity, I have created.

        Case #1:
        I receive data including Service Order ID into staging need to populate target. I can’t do just like that because of Service Order ID field property on the target, which does not allow to modify field value on insert. Option 1 – change target table field property, which could be done only using overleyering, not as extension. Option 2 – get field on target populated via X++ code, but I’m not sure how, which event to use.

        Case #2:
        I don’t have Service Order ID in staging. Need to populate target field from numberseq.


  3. Ievgen Miroshnikov March 27, 2017 / 9:44 pm

    For Case #1 try skip validation using next code

    public void persistEntity(DataEntityRuntimeContext _entityCtx)
    this.skipDataSourceValidateField(fieldNum(MyEntityName, ServiceOrderID), true);


    For Case #2 look at NumberSeqRecordFieldHandler::enableNumberSequenceControlForField() method and it’s usage.

  4. AnithaEswaran October 25, 2017 / 5:09 am


    Can this method be used for processing the data after export also ?

    For instance, I need to clean up few of the customized tables after the export is done.

    • Ievgen Miroshnikov October 25, 2017 / 6:12 am

      I don’t think that there is one or at least I’m not aware of it. There is always a dirty way to do stuff, you can create post event handler for copyTargetToStaging method of DMFEntityBase class, it is triggered for each entity, so will have performance impact…

  5. Mohsin February 14, 2018 / 10:52 pm

    Do entity execution times include this method completion as well?

      • Mohsin February 15, 2018 / 11:09 pm

        When we see the log we see a start and end time for the entity import, does that time include the postTargetProcess method execution as well?

  6. Brad Bateman February 28, 2018 / 2:41 pm

    Do you know how this works in the context of header/lines composite entities?

    For example: say I have a composite entity for invoice journals, which contains 2 entities, one for header and one for lines. Then I add postTargetProcess method to the header entity, and wanted to use it to post transactions after all processing for the header and lines was complete, would that be an option? Or would the header entity postTargetProcess method be called before the lines were sent to the target, since the lines are a separate entity that have to be created after the header exists?

    • Ievgen Miroshnikov February 28, 2018 / 6:20 pm

      Hi Brad, to be honest I don’t know. But it’s easy to find out. Just put a breakpoint there. I suspect it will call it for each entity, but you need to check.

  7. Marjorie Tecson July 10, 2018 / 3:33 pm

    postTargetProcess() method only gets called when the import is successful for at least one of the records. In case all the data from the file errors out, and we still want to perform some post processing logic, do you know which method to use for that?

Leave a Reply to Ievgen Miroshnikov Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s