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

D365O - How to add financial dimension in grid

This post outlines the steps; how to add financial dimensions (segmented control) in a grid in D365O. Let's assume we are adding new table and form for below explanation; New table contains two fields  AccountType and  LedgerDimension with relation to DimensionAttributeValueCombination table  Form looks like this; Set properties for segmented control under form design; - Auto declaration = Yes - Account type field = AccountType - Controller class = DimensionDynamicAccountController - Filter expression = %1 1. Override modified method for LedgerDimension field under form's datasource 2. Override lookup and checkUserCustomLookup method on ledger dimension segmented control in form desgin Datasource | D365O_FinancialDimension | LedgerDimension | modified [DataSource]     class D365O_FinancialDimension     { ...

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...

Another step closer - Finance Operations data in Power Platform - Virtual Entities

This post focuses on the integration technologies available to have the Microsoft Dynamics 365 Finance Operations data available in Dataverse/Common Data Services/CDS. What could be better then having The biggest ERP system's data in Power Platform. You can Power Portals, Power Apps, Power BI analytical reports, use power virtual agents for inventory closing and year end closing processes, manage expenses and employee/contractors time entry processes, most of these processes can be even without logging to MS ERP (Dynamics 365 Finance Operation) so can safe on license cost too.  Let's see what options are available to integrate F&O data with Power Platform however, this post is dedicated to Virtual Entities.  3 Options available out-the-box to integrate F&O data with Power Platform; 👉  Data Integrator  - Click on link to read more 👉  Dual-Write  -  Click on link to read more 👉  Virtual Entities - MS Tech Talk on Virtual entities   ...