Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Setting up schedule for CDS synchronization

Posted on by 477

Greetings,

I am trying to add a synchronization recurring job for a custom integration mapping I created.

However, I do not see where I am suposed to define which integration it is synching. When I look at the default jobs in the queue, none indicate which integration it is running.

Mine simply give this error:

A RecordID from table '' cannot be used with a record from table 'Integration Table Mapping'.

Any idea what I am doing wrong?

Cheers

  • Hedi Daneels Profile Picture
    Hedi Daneels 477 on at
    RE: Setting up schedule for CDS synchronization

    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;
    

    Cheers
  • WeeGrafter Profile Picture
    WeeGrafter 140 on at
    RE: Setting up schedule for CDS synchronization

    Hi,

    Sorry to jump on this ticket, I'm encountering the same error when running the standard Customer - Common Data Service Synchronization Job in BC Saas 19.4 GB

    5516.MicrosoftTeams_2D00_image.png

    What exactly did you do to resolve your own issue?

    Any help would be greatly apprecaited.

  • Suggested answer
    Hedi Daneels Profile Picture
    Hedi Daneels 477 on at
    RE: Setting up schedule for CDS synchronization

    Hi,

    I found what i needed in the recreate job internal procedure. Thank you.

    Cheers

  • Verified answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Setting up schedule for CDS synchronization

    Hi,

    Ah yes, I did miss the custom integration part in your posting. What you want is discussed here:

    docs.microsoft.com/.../walkthrough--customizing-microsoft-dynamics-crm-integration-in-dynamics-nav

    Under Tip:

    If you want to learn how to schedule the synchronization by using a job queue entry, examine the code on the RecreateJobQueueEntry function in codeunit 5330 CRM Integration Management and see how it is called by the integration code for other Microsoft Dynamics 365 for Sales entities in the codeunit.

    Thanks.

  • Hedi Daneels Profile Picture
    Hedi Daneels 477 on at
    RE: Setting up schedule for CDS synchronization

    Hi Marco,

    I am sorry, that was not the question.

    The question is how do you add a NEW scheduler, not edit an existing one.

    Adding a new scheduler using that option, gives the error mentioned in my first post.

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Setting up schedule for CDS synchronization

    Hello,

    From here you can define the schedule:

    pastedimage1603721711143v1.png

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,302 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans