Want to see the inbound and outbound Payload for dual-write integration

Let's continue where we left in first post "What got changed (Technical) in D365 Finance Operations with dual-write" our journey to understand what are the technical changes being done for dual-write framework.

This post we will look at what are highly used tables, entities, and classes involved for dual-write sync. I will only cover few tables, classes, and data entities but complete list of objects can be explored from AOT as shown below.











Business scenario: Create or update Vendor Groups in FO and sync over to CDS and vice versa.

Open Vendor groups screen - Accounts Payable > Vendors > Vendor groups







Out-of-the-box dual-write template is available for vendor groups





These fields are mapped between Finance and Operations apps and Common Data Service for Vendor groups dual-write template.

NOTE: only data will sync between apps only for mapped fields and the integration will also only trigger when we change data for these mapped fields in either side of the integration apps (FO or CDS) provided the sync direction is set to bi-directional (which is set for this scenario).








Requirement: You want to debug the integration (outbound or inbound)

Two important classes:

1. DualWriteSyncInbound

2. DualWriteSyncOutbound

If you want to debug data going out of FO to CDS (Outbound) then put a breakpoint at method WriteEntityRecordToCDS() of class DualWriteSyncOutbound.

This is quite extensive method and also gets a payload going out of FO to CDS, this payload can be watched and changed using all debugging features of D365 Finance and Operations.

Method BuildCDSPayload() being called inside method WriteEntityRecordToCDS() creates complete payload.

Pasting this just for reference purpose, this is subject to change at anytime so always refer to the updated code.

internal str BuildCDSPayload(str cdsLookupUrls, common
entityRecord,
str fieldMappingJson, ICDSSyncProvider
syncProvider)


    {


        var executionMarkerUniqueIdentifier
= newGuid();


        DualWriteSyncLogger::LogExecutionMarker('DualWriteOutbound.BuildCDSPayload', true, strFmt('Execution start for record %1 with
uniqueId %2'
,
entityRecord.RecId, executionMarkerUniqueIdentifier));


        CDSPayloadGenerator payloadGenerator =
syncProvider.CDSPayloadGenerator;


          
responseContract.DualWriteProcessingStage =
DualWriteProcessingStage::TransformingSourceData;


       


          
FieldMappingIterator fieldMappingIterator = FieldMappingIterator::ReadJson(fieldMappingJson);


        if (fieldMappingIterator == null)


        {


           
responseContract.AddRecordResponse(ExecutionStatus::Failed, strFmt(
"@DualWriteLabels:InvalidFieldMapping",fieldMappingJson), '');


            DualWriteSyncLogger::LogSyncError('BuildCDSPayload', '', '',
strFmt(
'Failed to create CDS payload.
Error reason %1'
,
responseContract.GetFormattedResponseObject()),
DualWriteDirection::Outbound);


        }


        while
(fieldMappingIterator.MoveNext())


        {


            FieldMapping fieldMapping =
fieldMappingIterator.Current();


            var valueTranforms =  fieldMapping.ValueTransforms;


            var sourceValue = this.FetchSourceFieldDataFromMapping(entityRecord,fieldMapping);


            // If there is a value default value transform then
the payload creation is skipped


            // The payload gets added in CDSSyncProvider


            boolean
skipPayloadCreation =
false;


            if (valueTranforms != null)


            {


                var
transformEnum = 
valueTranforms.GetEnumerator();


                while
(transformEnum.MoveNext())


                {


                    IValueTransformDetails
transform = transformEnum.Current;


                    sourceValue = this.ApplyValueTransform(transform, sourceValue);


                   


                    skipPayloadCreation =
(syncProvider.GetProviderType() != CDSSyncProviderType::CDSQueueSync &&


                        transform.TransformType
== ValueTransformType::Default);


                    if (transform.HasTransformationFailed)


                    {


                       
responseContract.AddFailedFieldResponse(fieldMapping.SourceField,
strFmt(
"@DualWriteLabels:FailedTransform", sourceValue,
fieldMapping.SourceField, enum2Str(transform.TransformType)),
'');


                    }


                }


            }


            if (!strContains(fieldMapping.DestinationField,'.') || fieldMapping.IsSystemGenerated)


            {


                if
(!skipPayloadCreation)


                {


                   
payloadGenerator.AddAttributeValuePair(fieldMapping.DestinationField,


                            sourceValue,


                           
fieldMapping.IsDestinationFieldQuoted,


                            this.FetchSourceFieldTypeCode(entityRecord,
fieldMapping));


                }


            }


           
syncProvider.AddSourceColumnTransformedValue(syncProvider.GetMappingKey(fieldMapping.SourceField
,fieldMapping.DestinationField) ,sourceValue);


        }


       


       
responseContract.DualWriteProcessingStage =
DualWriteProcessingStage::ResolvingLookups;


        var cdsPayLoad =
syncProvider.BuildCDSPayloadForLookups(cdsLookupUrls, fieldMappingJson);


        DualWriteSyncLogger::LogExecutionMarker('DualWriteOutbound.BuildCDSPayload', false, strFmt('Execution ends for record %1 with
uniqueId %2'
,
entityRecord.RecId, executionMarkerUniqueIdentifier));


        return cdsPayLoad;


    }

To debug data coming in FO from CDS (Inbound) then put a breakpoint at method WriteDataToEntity() of class DualWriteSyncInbound.

Pasting this just for reference purpose, this is subject to change at anytime so always refer to the updated code.

private ResponseContract WriteDataToEntity(str entityName, str entityFieldValuesJson, str companyContext, booleanrunValidations = false, boolean isDelete = false, DualWriteTransactionId transactionId = '', str CDSSyncVersion = '', boolean isBatchCommit = true)
    {
        var executionMarkerUniqueIdentifier = newGuid();             
        this.InitializeInboundSync(entityName);        
        returnreponseContract;
    }


Comment List
Related
Recommended