Hi,
As you can see from the date, this is from a long time ago. But maybe one of those points can help. Those are exctract from my entire sync file. This is of course not the best way to do it, but its the way I did it couple of years ago, and no issues till now.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Integration Management", 'OnIsIntegrationRecord', '', true, true)]
local procedure HandleOnIsIntegrationRecord(TableID: Integer; var isIntegrationRecord: Boolean)
begin
if TableID = DATABASE::MyCustomTable then
isIntegrationRecord := true;
end;
local procedure InsertIntegrationTableMapping(var IntegrationTableMapping: Record "Integration Table Mapping"; MappingName: Code[20]; TableNo: Integer; IntegrationTableNo: Integer; IntegrationTableUIDFieldNo: Integer; IntegrationTableModifiedFieldNo: Integer; TableConfigTemplateCode: Code[10]; IntegrationTableConfigTemplateCode: Code[10]; SynchOnlyCoupledRecords: Boolean)
begin
IntegrationTableMapping.CreateRecord(MappingName, TableNo, IntegrationTableNo, IntegrationTableUIDFieldNo, IntegrationTableModifiedFieldNo, TableConfigTemplateCode, IntegrationTableConfigTemplateCode, SynchOnlyCoupledRecords, IntegrationTableMapping.Direction::FromIntegrationTable, 'CDS');
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"CDS Setup Defaults", 'OnBeforeResetConfiguration', '', true, true)]
local procedure HandleOnOnBeforeResetConfiguration(CDSConnectionSetup: Record "CDS Connection Setup"; var IsHandled: Boolean)
var
CDSCustom: Record "CDS cre123_MyCustomTable"; //cds table
CustomTable: Record MyCustomTable; //bc table
IntegrationFieldMapping: Record "Integration Field Mapping";
IntegrationTableMapping: Record "Integration Table Mapping";
begin
InsertIntegrationTableMapping(
IntegrationTableMapping, 'CUSTOMTABLE1',
DATABASE::MyCustomTable, DATABASE::"CDS cre123_MyCustomTable",
CDSCustom.FieldNo(cre123_CustomId), CDSCustom.FieldNo(ModifiedOn),
'', '', false);
IntegrationTableMapping.Modify();
globalParam.get('CREATEJOBS');
if (globalParam.TextWaarde = 'TRUE') then
RecreateJobQueueEntryFromIntTableMapping(IntegrationTableMapping, 30, true, 30, 'CRM CDS CustomTable');
InsertIntegrationFieldMapping('CUSTOMTABLE1', CustomTable.FieldNo(cr123_CUSTOM1), CDSCustom.FieldNo(cr123_CUSTOM1), IntegrationFieldMapping.Direction::FromIntegrationTable, '', true, false);
InsertIntegrationFieldMapping('CUSTOMTABLE1', CustomTable.FieldNo(cr123_CUSTOM2), CDSCustom.FieldNo(cr123_CUSTOM2), IntegrationFieldMapping.Direction::FromIntegrationTable, '', true, false);
IsHandled := true;
end;
procedure InsertIntegrationFieldMapping(IntegrationTableMappingName: Code[20]; TableFieldNo: Integer; IntegrationTableFieldNo: Integer; SynchDirection: Option; ConstValue: Text; ValidateField: Boolean; ValidateIntegrationTableField: Boolean)
var
IntegrationFieldMapping: Record "Integration Field Mapping";
begin
IntegrationFieldMapping.CreateRecord(IntegrationTableMappingName, TableFieldNo, IntegrationTableFieldNo, SynchDirection,
ConstValue, ValidateField, ValidateIntegrationTableField);
end;
local procedure GetTableFilterFromView(TableID: Integer; Caption: Text; View: Text): Text
var
FilterBuilder: FilterPageBuilder;
begin
FilterBuilder.AddTable(Caption, TableID);
FilterBuilder.SetView(Caption, View);
exit(FilterBuilder.GetView(Caption, false));
end;
local procedure RecreateJobQueueEntryFromIntTableMapping(IntegrationTableMapping: Record "Integration Table Mapping"; IntervalInMinutes: Integer; ShouldRecreateJobQueueEntry: Boolean; InactivityTimeoutPeriod: Integer; ServiceName: Text)
var
JobQueueEntry: Record "Job Queue Entry";
begin
JobQueueEntry.SetRange("Object Type to Run", JobQueueEntry."Object Type to Run"::Codeunit);
JobQueueEntry.SetRange("Object ID to Run", Codeunit::"Integration Synch. Job Runner");
JobQueueEntry.SetRange("Record ID to Process", IntegrationTableMapping.RecordId());
JobQueueEntry.DeleteTasks();
JobQueueEntry.InitRecurringJob(IntervalInMinutes);
JobQueueEntry."Object Type to Run" := JobQueueEntry."Object Type to Run"::Codeunit;
JobQueueEntry."Object ID to Run" := Codeunit::"Integration Synch. Job Runner";
JobQueueEntry."Record ID to Process" := IntegrationTableMapping.RecordId();
JobQueueEntry."Run in User Session" := false;
JobQueueEntry.Description :=
CopyStr(StrSubstNo(JobQueueEntryNameTok, IntegrationTableMapping.Name, ServiceName), 1, MaxStrLen(JobQueueEntry.Description));
JobQueueEntry."Maximum No. of Attempts to Run" := 10;
JobQueueEntry.Status := JobQueueEntry.Status::Ready;
JobQueueEntry."Rerun Delay (sec.)" := 30;
JobQueueEntry."Inactivity Timeout Period" := InactivityTimeoutPeriod;
if ShouldRecreateJobQueueEntry then
Codeunit.Run(Codeunit::"Job Queue - Enqueue", JobQueueEntry)
else
JobQueueEntry.Insert(true);
end;