Skip to main content

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

    {

        var executionMarkerUniqueIdentifier = newGuid();             

        this.InitializeInboundSync(entityName);        

        return reponseContract;

    }


Comments

Popular posts from this blog

The Dual Write implementation - Part 1 - Understand and Setup

What is Dual-write? Tightly couples – complete at one transaction level Near real time Bi-directional Master data and business documents – Customer records you are creating and modifying and at this document we are talking about sales orders or quotes and invoice. Master data could be reference data e.g. customer groups and tax information Why Dual-write and why not Data Integrator? Data Integrator is Manual or Scheduled One directional Now, Let's deep dive and understand what is required for Dual-write setup and from where to start. First thing first, check you have access to https://make.powerapps.com/ Choose right environment of CDS (CE) Make sure you have access to the environment too, click on gear icon and Admin Center  Look for required environment and Open it, you must have access as going forward you are going to configure dual write steps in the environment user the same user you are logged in now. Now, go back to power platform admin center and...

D365FO: Entity cannot be deleted while dependent Entities for a processing group exist. Delete dependent Entities for a processing group and try again.

Scenario: There are times when you want to delete an entity from target entity list and when you do so, you face an error message which does not tell you where exactly the entity has been used.  "Entity cannot be deleted while dependent Entities for the processing group exist. Delete dependent Entities for a processing group and try again. " Solution: Browse the environment by appending this part  /?mi=SysTableBrowser&TableName=DMFDefinitionGroupEntity&cmp=USMF   at the end.  For example; if the environment URL is  https://daxture.sandbox.operations.dynamics.com then the complete URL will be https://daxture.sandbox.operations.dynamics.com/?mi=SysTableBrowser&TableName=DMFDefinitionGroupEntity&cmp=USMF Filter for Entity and it will give you the DefinitionGroup where the entity has been added or used in data management import/export projects. Get the DefinitionGroup name and search in the export/import projects under data management and either del...

Dual-write connection set error: An item with the same key has already been added

If you happen to see this error message then you have duplicate records in cdm_company entity in CDS environment. Check for cdm_companycode field this is normally not allowed but have a look and delete the ones with duplicates.