web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Dataverse Connection Setup with a table have multiple primary keys

(7) ShareShare
ReportReport
Posted on by 42
Hello, i have a custom table named /CX Timesheet/. and this table has fields /Project/ and /Project Task/ related Job and Job Task tables. When I add a record from dataverse and run full sync, it gives below error.

The data could not be updated because of the following error: The field Project Task of table CX Timesheet contains a value (JOB00010) that cannot be found in the related table (Job Task).
 
Project field is working but /Project Task/ field gives error because the value /JOB00010/ is job no. not job task no. How can i correct this issue?
 
Field Mapping:
GeneralHelper.InsertIntegrationFieldMapping(
 'Timesheet-Timesheet',
 CX_Timesheet.FieldNo(ProjectNo),
 DataverseTimesheet.FieldNo(cr334_Project),
 IntegrationFieldMapping.Direction::Bidirectional, '', true,false);
 
GeneralHelper.InsertIntegrationFieldMapping(
 'Timesheet-Timesheet',
 CX_Timesheet.FieldNo(ProjectTaskNo),
 DataverseTimesheet.FieldNo(cr334_ProjectTask),
 IntegrationFieldMapping.Direction::Bidirectional, '', true,false);
       
 
Custom table definition:
field(49; ProjectNo; Code[50])
        {
            Description = '';
            Caption = 'Project';
            TableRelation = /Job/./No./;
        }
        field(51; ProjectTaskNo; Code[50])
        {
            Description = '';
            Caption = 'Project Task';
            TableRelation = /Job Task/./Job Task No./ where(/Job No./ = field(/ProjectNo/));
        }
I have the same question (0)
  • Suggested answer
    Nour_K Profile Picture
    83 on at

    Hello,

    I encountered a very similar issue with dependent composite keys when syncing custom tables with Dataverse. The problem here is rooted in how Business Central processes integration field mappings linearly.

    Because the standard Job Task table uses a composite primary key (Job No. + Job Task No.), your validation rule on ProjectTaskNo expects the parent ProjectNo to already be settled and matching. During a full sync, the engine is trying to push the parent project code (JOB00010) directly into your task field before the transaction is fully settled, which immediately trips the table relation and crashes the sync block.

    To resolve this, I found it best to turn off the immediate inline field validation inside the integration mapping setup. By changing your ValidateField parameter (the 6th parameter) from true to false for the task field, you stop the integration engine from throwing a validation error mid-stream before it has finished transferring all related fields:

    GeneralHelper.InsertIntegrationFieldMapping(
     'Timesheet-Timesheet',
     CX_Timesheet.FieldNo(ProjectTaskNo),
     DataverseTimesheet.FieldNo(cr334_ProjectTask),
     IntegrationFieldMapping.Direction::Bidirectional, '', 
     false, // Changed to false to prevent early validation crashes
     false);

     

    After disabling the default inline validation, we can safely handle the data validation ourselves once the record fields are fully transferred. I handle this by subscribing to the OnAfterTransferRecordFields event in Codeunit::"Integration Record Synch.". This allows us to double-check the incoming values from Dataverse, ensure the proper task string is assigned, and then manually run the validations in the correct architectural order.

    Here is the subscriber code I use to handle this scenario:

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Integration Record Synch.", 'OnAfterTransferRecordFields', '', true, true)]
    local procedure HandleTimesheetCompositeKeys(SourceRecordRef: RecordRef; DestinationRecordRef: RecordRef; var AdditionalFieldsModified: Boolean; DestinationIsSource: Boolean)
    var
        DataverseTimesheet: Record "Dataverse Timesheet"; // Replace with your actual Dataverse table name
        CX_Timesheet: Record "CX Timesheet";
    begin
        if DestinationRecordRef.Number <> Database::"CX Timesheet" then
            exit;
        // Running when Source is Dataverse and Destination is Business Central
        if not DestinationIsSource then begin
            SourceRecordRef.SetTable(DataverseTimesheet);
            DestinationRecordRef.SetTable(CX_Timesheet);
            // If Dataverse is accidentally passing the parent project info into the task field, 
            // you can manually correct it or safely evaluate it here before final validation
            if CX_Timesheet.ProjectTaskNo = CX_Timesheet.ProjectNo then begin
                // CX_Timesheet.ProjectTaskNo := DataverseTimesheet.cr334_ActualTaskCodeField;
                
                // Now we validate them in the proper sequential order
                CX_Timesheet.Validate(ProjectNo);
                CX_Timesheet.Validate(ProjectTaskNo);
                
                DestinationRecordRef.GetTable(CX_Timesheet);
                AdditionalFieldsModified := true;
            end;
        end;
    end;

    Double-check your Dataverse column data to ensure cr334_ProjectTask is genuinely holding the task code string and not an alternate primary lookup value, and this combination of turning off inline validation and using the post-transfer subscriber will get your sync running smoothly.

    Let me know if this solves the issue for you!

  • mertadsay Profile Picture
    42 on at
    @Nour_K thanks for your answer, its very helpful but its not the exact solution to my issue becuse cr334_ProjectTask column is not a text column. its lookup column. when the column is a text column i dont face the issue at all.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,382 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,625 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,376

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans