Data Management handle project finished running

If you only want to know how to determine if a project has finished running go to Step 2: determine  when a project has finished executing.

In a Data Management project there might be several entities in which data is to be inserted. Knowing when all these entities have finished executed is not straight forward. A customer wanted to post a journal automatically that was created by a Data Management project.

In this example I will explain how to mark a journal for posting and posting the journal created [via Data Management] after the project has finished executed.

Step 1: mark the journal for posting

Create a table to store which journals to post, RefrecId or JournalId, whatever is best in your case. 

In my case it looked like this:


Of the entity in which your journal is inserted, create a data event handler on inserted event type

   [DataEventHandler(tableStr(PDIJournalTableEntity), DataEventType::Inserted)]

    public static void PDIJournalTableEntity_onInserted(Common sender, DataEventArgs e)
    {
        PDIJournalTableEntity   journalEntity   = sender;

        InspPDIJournalTableToPost::insertToPost(journalEntity);             

  }


 Method insertToPost inserts a new row in table.

Step 2: determine  when a project has finished executing

To do so you need the project name (DefinitionGroup), this is probably best to create a parameter for. In this example I've hard coded the project name as 'PDI Journal', same as in image above. 

Create a data event handler on table DMFDefinitionGroupExecutionHistory for the Inserted data event type. Check if "your" project name, if so run a check if all entities in the project has finished executing.  This is done by counting the number of active steps up against finished executed in history table. 

    [DataEventHandler(tableStr(DMFDefinitionGroupExecutionHistory), DataEventType::Inserted)]

    public static void DMFDefinitionGroupExecutionHistory_onInserted(Common sender, DataEventArgs e)
    {
        DMFDefinitionGroupExecutionHistory  executionHistory = sender;
        DMFDefinitionGroupExecutionHistory  checkExecutionHistory;
        DMFDefinitionGroupEntity            definitionGroupEntity;

        //TODO: add parameter for definition group
        if(executionHistory.DefinitionGroup == 'PDI Journal')
        {
            select count(RecId)
                from definitionGroupEntity
                    where   definitionGroupEntity.DefinitionGroup   == executionHistory.DefinitionGroup
                    &&      definitionGroupEntity.Disable           == NoYes::No;

            select count(RecId)
                from checkExecutionHistory
                    where   checkExecutionHistory.DefinitionGroup   == executionHistory.DefinitionGroup
                    &&  checkExecutionHistory.ExecutionId           == executionHistory.ExecutionId
                    &&  checkExecutionHistory.StagingStatus         == DMFBatchJobStatus::Finished
                    &&  checkExecutionHistory.TargetStatus          == DMFBatchJobStatus::Finished;

            
            if(definitionGroupEntity.RecId == checkExecutionHistory.RecId)
            {
                //indicates that all entities in the import project has runned successfully
                InspPDIJourPostAsync inspPDIJourPostAsync = InspPDIJourPostAsync::construct();
                inspPDIJourPostAsync.run();
            }
        }

    }

Comments

Popular posts from this blog

Call a simple Logic app from X++

SysOperationFramework with use of Query

Retail Attributes on sales lines