Sunday, October 11, 2020

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)





                            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, boolean runValidations = false, boolean isDelete = false, DualWriteTransactionId transactionId = '', str CDSSyncVersion = '', boolean isBatchCommit = true)


        var executionMarkerUniqueIdentifier = newGuid();             


        return reponseContract;


1 comment:

  1. Investment plansPROMO PACKAGE ?? BASIC Invest $70 earn $600 Invest $100 earn $1000  Invest $200 earn $2,000  Invest $300 earn $3,500  Invest $400 earn $4,500  Invest $500 earn $6,000 
    ?? PRO  Invest $1,000 earn $15,000  Invest $2,000 earn $25,000  Invest $3,000 earn $35,000  Invest $4,000 earn $45,000  Invest $5,000 earn $60,000  Invest $10,000 earn $100,000. 
    ?? PREMIUM  1BTC earn 5BTC  2BTC earn 10BTC  3BTC earn 16BTC  4BTC earn 22BTC  5BTC earn 30BTC. 
    MODE OF PAYMENT. Any, Suitable For Investors, But Terms and Conditions Apply.
    ??HURRY NOW!!! Refer a Friend or Family member to invest same time, and Receive an instant $50 Reward. 
    To set up an INVESTMENT PLAN, Contact Admin:
    WhatsApp: +1(929)390-8581


I will appreciate your comments !

Download large bacpac (sandbox database) to DEV environment much faster

As the LCS website gets slower and slower and the database backups get bigger and bigger.  Use AZCopy to download objects out of LCS asset l...