Sync your BC data to Dataverse with less code

Sync your BC data to Dataverse with less code

As almost all people know there is a sync between Business Central and Dataverse. With this sync you can sync your Business Central data with Dataverse and use it in your apps/pages etc. Your data will be there in Dataverse.
In general there are only 8 tables available in the standard connection:

(employee isn’t a standard table)

You can add your own tables by using a walkthrought written by Microsoft. This guide you can find here:
Customizing an Integration with Microsoft Dataverse – Business Central | Microsoft Docs

If you have already done that you know it will be allot of coding. And mostly it is also the same code again per table with a little difference.

So I though it must be easier through a UI. My first try you can find here on Github:
Bertverbeek4PS/DataverseSyncUI (github.com)

First you must create a Dataverse table into Business Central with the altpgen.exe tool:

-project:<Your AL project folder>
-packagecachepath:<Your AL project cache folder>
-serviceuri:<Microsoft Dataverse server URL>
-entities:cds_worker
-baseid:50000

After you have done this you must create a page extension on the page that you want a sync:

pageextension 70100 "Employee Synch Extension" extends "Employee Card"
{
    actions
    {
        addlast(navigation)
        {
            group(ActionGroupCDS)
            {
                Caption = 'Dataverse';
                Visible = CDSIntegrationEnabled;

                action(CDSGotoWorker)
                {
                    Caption = 'Worker';
                    Image = CoupledCustomer;
                    ApplicationArea = All;
                    ToolTip = 'Open the coupled Dataverse worker.';

                    trigger OnAction()
                    var
                        CRMIntegrationManagement: Codeunit "CRM Integration Management";
                    begin
                        CRMIntegrationManagement.ShowCRMEntityFromRecordID(rec.RecordId);
                    end;
                }
                action(CDSSynchronizeNow)
                {
                    Caption = 'Synchronize';
                    ApplicationArea = All;
                    Visible = true;
                    Image = Refresh;
                    Enabled = CDSIsCoupledToRecord;
                    ToolTip = 'Send or get updated data to or from Microsoft Dataverse.';

                    trigger OnAction()
                    var
                        CRMIntegrationManagement: Codeunit "CRM Integration Management";
                    begin
                        CRMIntegrationManagement.UpdateOneNow(rec.RecordId);
                    end;
                }
                action(ShowLog)
                {
                    Caption = 'Synchronization Log';
                    ApplicationArea = All;
                    Visible = true;
                    Image = Log;
                    ToolTip = 'View integration synchronization jobs for the customer table.';

                    trigger OnAction()
                    var
                        CRMIntegrationManagement: Codeunit "CRM Integration Management";
                    begin
                        CRMIntegrationManagement.ShowLog(rec.RecordId);
                    end;
                }
                group(Coupling)
                {
                    Caption = 'Coupling';
                    Image = LinkAccount;
                    ToolTip = 'Create, change, or delete a coupling between the Business Central record and a Microsoft Dataverse row.';

                    action(ManageCDSCoupling)
                    {
                        Caption = 'Set Up Coupling';
                        ApplicationArea = All;
                        Visible = true;
                        Image = LinkAccount;
                        ToolTip = 'Create or modify the coupling to a Microsoft Dataverse Worker.';

                        trigger OnAction()
                        var
                            CRMIntegrationManagement: Codeunit "CRM Integration Management";
                        begin
                            CRMIntegrationManagement.DefineCoupling(rec.RecordId);
                        end;
                    }
                    action(DeleteCDSCoupling)
                    {
                        Caption = 'Delete Coupling';
                        ApplicationArea = All;
                        Visible = true;
                        Image = UnLinkAccount;
                        Enabled = CDSIsCoupledToRecord;
                        ToolTip = 'Delete the coupling to a Microsoft Dataverse Worker.';

                        trigger OnAction()
                        var
                            CRMCouplingManagement: Codeunit "CRM Coupling Management";
                        begin
                            CRMCouplingManagement.RemoveCoupling(rec.RecordId);
                        end;
                    }
                }
            }
        }
    }

    trigger OnOpenPage()
    begin
        CDSIntegrationEnabled := CRMIntegrationManagement.IsCDSIntegrationEnabled();
    end;

    trigger OnAfterGetCurrRecord()
    begin
        if CDSIntegrationEnabled then
            CDSIsCoupledToRecord := CRMCouplingManagement.IsRecordCoupledToCRM(rec.RecordId);
    end;

    var
        CRMIntegrationManagement: Codeunit "CRM Integration Management";
        CRMCouplingManagement: Codeunit "CRM Coupling Management";
        CDSIntegrationEnabled: Boolean;
        CDSIsCoupledToRecord: Boolean;

}

And that is all the coding that you have to do. The rest is via the UI of BC webclient.

In BC you can go to Dataverse tables and setup the Sync between BC and Dataverse:

Also you can map the fields:

Especially mention the column “Field on CDS Page”. Here you can put the fields that you want to see on the Dataverse page.

After you have done this you must run the “Use Default Synchronisation Setup” action on the “Dataverse Connection Setup”:

Now you are ready to sync your data:

If you have sync your data you can go (in this case the employee) to the record and show the coupling:

And also show the list of all records in Dataverse via the look-up:

And yes there is some coding in here. But that is because of the page extension and you need the CDS table. But everything else can be done via the UI.

Do you have any comments? Feel free to contact me or create a pull request.

Hopefully Microsoft will start to move slowly to a UI setup of this great and stable feature!

Some more info about Dataverse you can find here:
Dataverse – Discover Microsoft Business Central (bertverbeek.nl)

7 COMMENTS

HenrySitly

regardful

Darren

Could you help me with codeunit code to simply add CustomerNo to IntegrationFieldMapping for CUSTOMER table with dataverse sync?

I want to map Customer.CustomerNo to Account.accountcode in CRM.

Will compensate for help!

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.