Data Entity: Methods to Update Target Table D365 FO X++
Recently we got a requirement to update the target table
with the execution id and show the status of the Entity status on the Dynamics
AX Form.
In this case, we can use the method “PostTargetProcess” method, which allows you to
use DMFDefinitionGroupExecution from
where we can get the Entity DefinitionGroup and Execution Id.
This method is automatically called by the Framework class DMFEntityWriter at the end of processRecords() method.
ProcessRecords() method will process all the records transferred
from staging to target.
In the below example, we are
updating the LedgerJournalTable with ExecutionID, which is used to display the
status (error/ completed, etc ) based on execution id.
[ExtensionOf(tableStr(DataEntity))]
final public class DataEntity_Extension
{
public static void
postTargetProcess(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
{
LedgerJournalEntityStaging
staging;
LedgerJournalTable ledgerJournalTableloc;
select
firstonly JournalBatchNumber,ExecutionId from staging
where
staging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup
&& staging.ExecutionId ==
_dmfDefinitionGroupExecution.ExecutionId;
if
(staging.JournalBatchNumber)
{
ledgerJournalTableloc =
LedgerJournalTable::find(staging.JournalBatchNumber);
if (ledgerJournalTableloc.RecId &&
ledgerJournalTableloc.MessageId != staging.ExecutionId)
{
ttsbegin;
ledgerJournalTableloc.selectForUpdate(true);
ledgerJournalTableloc.MessageId = _dmfDefinitionGroupExecution.ExecutionId;
ledgerJournalTableloc.update();
ttscommit;
}
}
}
}
Like postTargetProcess, we have a method called “PostGetStagingData” this method
is used to update the data before it gets inserted into the staging
table.
public static void
postGetStagingData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
{
//logic here
}
No comments:
Post a Comment