User Tools

Site Tools


en:ondemandreplication

eeRis Sprinkler v.19.4
for Microsoft Dynamics 365 Business Central v.19.x

<HTML><H3>“On Demand” Replication Function using C/AL Code</H3></HTML>

With Sprinkler, developers can use the new “On Demand” replication function.

This feature will allow you to manage, for example, the following scenarios:

  • The automatic data export is not active, but you just want to replicate one or more records in the target database.
  • Before the activation of the automatic data export, you want to feed all the tables with current data (this operation was however already possible through manual Advanced Replication Functionality)
  • You want to build a test scenario with a series of predetermined data, and the operation must be repeatable.
  • You have to archive one or more tables data on a historical database: for example, sale and purchase documents with related tables, with [Posting Date] lower than a specified date.

There is a public Function of [Spk Management] codeunit that allows you to reach the goal:

Replicate_Record(parmRecord : Variant, Peer : GUID)

parmRecord: can be both Record and RecordRef type variable

Example - You need to replicate to a remote historical database the data of tables [Sales Invoice Header], [Sales Invoice Line] and corresponding [G/L Entry] so you can navigate those documents correctly. All the documents with [Posting Date] up to 12/31/2016 must be copied. We suppose that the schema of all involved tables are identical in Source and Target Peer's databases.

Before to start, in the Target Peer you have to create the following Importing Setup for all [Sales Invoice Header], [Sales Invoice Line] and [G/L Entry] tables: this setup will be active in ~1 minute; the user declared as [Data Distribution Service User] on Target Peer must have Insert and Modify permission on destination table. No further setup are required on Source Peer, because this function will send ALL fields belonging to source table. Of course, the user operating the following code must have the Permission Set EERIS SPK USER, and Read permissions on source table.

Solution - Create the following variables:

Name DataType SubType
SpkMgt Codeunit Spk Management
Peer Record Data Distrib. Peer
SalesInvHdr Record Sales Invoice Header
SalesInvLine Record Sales Invoice Line
GLEntry Record G/L Entry

The code is:

LastDate := 311220D;
Peer.GET('{60632e40-a50d-11e7-9598-0800200c9a66}');    //exemple of Remote Peer ID

SalesInvHdr.SETFILTER("Posting Date",'<=%1',LastDate);
IF SalesInvHdr.FINDSET THEN REPEAT
  SpkMgt.Replicate_Record(SalesInvHdr,Peer."Server ID");

  SalesInvLine.SETRANGE("Document No.",SalesInvHdr."No.");
  IF SalesInvLine.FINDSET THEN REPEAT
    SpkMgt.Replicate_Record(SalesInvLine,Peer."Server ID");
  UNTIL SalesInvLine.NEXT = 0;

  GLEntry.SETRANGE("Document Type",GLEntry."Document Type"::Invoice);
  GLEntry.SETRANGE("Document No.",SalesInvHdr."No.");
  IF GLEntry.FINDSET THEN REPEAT
    SpkMgt.Replicate_Record(GLEntry,Peer."Server ID");
  UNTIL GLEntry.NEXT = 0;

UNTIL SalesInvHdr.NEXT = 0;
en/ondemandreplication.txt · Last modified: 2021/01/28 16:46 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki