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.


9 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…

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s