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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Error when integrating "Ship-to Address" table from BusinessCentral with customeraddress table from Sales / dataverse

(5) ShareShare
ReportReport
Posted on by 325

Hello, 

We are trying to integrate Customer shipping address between BusinessCentral & Sales (CRM) for that we have created table mapping for "Ship-to Address" table from BusinessCentral with customeraddress table from dataverse. but when we do full sync, we are getting error as "The caption Address is ambiguous between multiple fields on the table CRM Customeraddress"

below is the codeunit for refrance, not sure what is wrong.

.

codeunit 50101 CDSDataverseEvent
{

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"CRM Setup Defaults", 'OnGetCDSTableNo', '', false, false)]
    local procedure HandleOnGetCDSTableNo(BCTableNo: Integer; var CDSTableNo: Integer; var handled: Boolean)
    begin
        if BCTableNo = DATABASE::"Ship-to Address" then begin
            CDSTableNo := DATABASE::"CRM Customeraddress";
            handled := true;
        end;
    end;


    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Lookup CRM Tables", 'OnLookupCRMTables', '', true, true)]
    local procedure HandleOnLookupCRMTables(CRMTableID: Integer; NAVTableId: Integer; SavedCRMId: Guid; var CRMId: Guid; IntTableFilter: Text; var Handled: Boolean)
    begin
        if CRMTableID = Database::"CRM Customeraddress" then
            Handled := LookupCDSCustomerAddress(SavedCRMId, CRMId, IntTableFilter);
    end;

    local procedure LookupCDSCustomerAddress(SavedCRMId: Guid; var CRMId: Guid; IntTableFilter: Text): Boolean
    var
        CDSCustomerAddress: Record "CRM Customeraddress";
        OriginalCDSCustomerAddress: Record "CRM Customeraddress";
        OriginalCDSCustomerAddressList: Page "CDS CustomerAddress List";    //ToDo - create a list page for CustomerAddress eg. CDS Lab Book List
    begin
        if not IsNullGuid(CRMId) then begin
            if CDSCustomerAddress.Get(CRMId) then
                OriginalCDSCustomerAddressList.SetRecord(CDSCustomerAddress);
            if not IsNullGuid(SavedCRMId) then
                if OriginalCDSCustomerAddress.Get(SavedCRMId) then
                    OriginalCDSCustomerAddressList.SetCurrentlyCoupledCDSCustomerAddress(OriginalCDSCustomerAddress);
        end;

        CDSCustomerAddress.SetView(IntTableFilter);
        OriginalCDSCustomerAddressList.SetTableView(CDSCustomerAddress);
        OriginalCDSCustomerAddressList.LookupMode(true);
        if OriginalCDSCustomerAddressList.RunModal = ACTION::LookupOK then begin
            OriginalCDSCustomerAddressList.GetRecord(CDSCustomerAddress);
            //CRMId := CDSCustomerAddress.CustomerAddressId;  //ToDo check primary key
            CRMId := CDSCustomerAddress.Name;
            exit(true);
        end;
        exit(false);
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"CRM Setup Defaults", 'OnAddEntityTableMapping', '', true, true)]
    local procedure HandleOnAddEntityTableMapping(var TempNameValueBuffer: Record "Name/Value Buffer" temporary);
    begin
        AddEntityTableMapping('Ship-to Address', DATABASE::"CRM Customeraddress", TempNameValueBuffer);
    end;

    local procedure AddEntityTableMapping(CRMEntityTypeName: Text; TableID: Integer; var TempNameValueBuffer: Record "Name/Value Buffer" temporary)
    begin
        TempNameValueBuffer.Init();
        TempNameValueBuffer.ID := TempNameValueBuffer.Count   1;
        TempNameValueBuffer.Name := CopyStr(CRMEntityTypeName, 1, MaxStrLen(TempNameValueBuffer.Name));
        TempNameValueBuffer.Value := Format(TableID);
        TempNameValueBuffer.Insert();
    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::Bidirectional, 'CDS');
    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;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"CDS Setup Defaults", 'OnAfterResetConfiguration', '', true, true)]
    local procedure HandleOnAfterResetConfiguration(CDSConnectionSetup: Record "CDS Connection Setup")
    var
        IntegrationTableMapping: Record "Integration Table Mapping";
        IntegrationFieldMapping: Record "Integration Field Mapping";
        CDSCustomerAddress: Record "CRM Customeraddress";
        ShipToAddress: Record "Ship-to Address";
    begin
        InsertIntegrationTableMapping(
            IntegrationTableMapping, 'Customeraddress',
            DATABASE::"Ship-to Address", DATABASE::"CRM Customeraddress", CDSCustomerAddress.FieldNo(Name), CDSCustomerAddress.FieldNo(ModifiedOn), '', '', true);

        InsertIntegrationFieldMapping('Customeraddress', ShipToAddress.FieldNo(Address), CDSCustomerAddress.FieldNo(Line1), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        InsertIntegrationFieldMapping('Customeraddress', ShipToAddress.FieldNo("Address 2"), CDSCustomerAddress.FieldNo(Line2), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        InsertIntegrationFieldMapping('Customeraddress', ShipToAddress.FieldNo(City), CDSCustomerAddress.FieldNo(City), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        InsertIntegrationFieldMapping('Customeraddress', ShipToAddress.FieldNo(County), CDSCustomerAddress.FieldNo(StateOrProvince), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        InsertIntegrationFieldMapping('Customeraddress', ShipToAddress.FieldNo("Post Code"), CDSCustomerAddress.FieldNo(PostalCode), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        InsertIntegrationFieldMapping('Customeraddress', ShipToAddress.FieldNo("Country/Region Code"), CDSCustomerAddress.FieldNo(Country), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);

        //InsertIntegrationFieldMapping('LabBook', LabBook.FieldNo(Title), CDSLabBook.FieldNo(cr703_Title), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        //InsertIntegrationFieldMapping('LabBook', LabBook.FieldNo(Author), CDSLabBook.FieldNo(cr703_Author), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        //InsertIntegrationFieldMapping('LabBook', LabBook.FieldNo(Hardcover), CDSLabBook.FieldNo(cr703_Hardcover), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
        //InsertIntegrationFieldMapping('LabBook', LabBook.FieldNo("Page Count"), CDSLabBook.FieldNo(cr703_PageCount), IntegrationFieldMapping.Direction::Bidirectional, '', true, false);
    end;

}

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    102,361 Super User 2026 Season 1 on at

    Hi, I merged your code with the code I tested.

    https://yzhums.com/17065/

    I think there is something wrong with the value of CRMId below.

    pastedimage1644977799273v1.png

    For example:

    pastedimage1644977896847v3.png

    pastedimage1644977865458v2.png

    Hope this will help.

    Thanks.

    ZHU

  • Vinayak Chingunde Profile Picture
    325 on at

    Hi Zhu,

    I used customeraddress.name because that's the primary key in dataverse.

    pastedimage1645047247816v1.png

    pastedimage1645047314691v2.png

    Now I am getting a different error: 

    An error occurred when communicating with Dataverse. Detailed description: The entity with a name = ' ' with namemapping = 'Logical' was not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=18904834, MinActiveRowVersion=18904834, MetadataInstanceId=13894122, LastUpdated=2022-02-14 10:18:58.367

    not sure why.

  • Vinayak Chingunde Profile Picture
    325 on at

    yzhums any thoughts, I am not able to find any solution yet.

  • Suggested answer
    YUN ZHU Profile Picture
    102,361 Super User 2026 Season 1 on at

    Hi, Sorry I just noticed I posted the wrong link.

    https://yzhums.com/17065/

    I think you should have run the following command.

    .\altpgen -project:"C:\Users\yzhu\Documents\AL\IntegrationWithDataverse" -packagecachepath:"C:\Users\yzhu\Documents\AL\IntegrationWithDataverse\packagecachepath" -serviceuri:"https://org792fe27a.crm.dynamics.com/" -entities:cr703_labbook -baseid:50100 -tabletype:CDS

    The line I pointed out should be the key of the Object that automatically generated.

    pastedimage1645668224535v1.png

    You can check my code to see if there are any other problems.

    Hope this will help.

    Thanks.

    ZHU

  • Community Member Profile Picture
    on at

    Vinayak- Did you get it to work? I am running into same issue.

  • Anita3184 Profile Picture
    36 on at
    Hi Everyone
    Was this resolved? I want to inetgrate the Dataverse customer addesses with Business Central and would like to know if anyone has successfully done this? Thanks
  • Suggested answer
    HV-28051321-0 Profile Picture
    6 on at
    I have added a table extension for CRM Customeraddress and changed the caption, for me that solved the issue.

  • Suggested answer
    Grigorios Mavrogeorgis Profile Picture
    2,721 Super User 2026 Season 1 on at
    Hi,
    your code structure is ok, looks like you took it from the LabBook custom integration example and changed it for addresses. But Customeraddress has some traps that the LabBook one does not have, this is why you get the duplicate/ambiguous mapping.

    First thing, in the table mapping you put CDSCustomerAddress.FieldNo(Name) as the unique id field.
    This is not correct, the UID has to be the GUID key which is CustomerAddressId, not Name. And in your lookup you also do CRMId := CDSCustomerAddress.Name but CRMId is a Guid, so again should be CustomerAddressId. From here already the coupling start to behave wrong.

    The bigger problem is the keys. Ship-to Address uses Customer No. plus Code together, but in Dataverse the customeraddress is linked to the account by ParentId. So a simple one to one bidirectional sync cannot know which address belong to which customer and you end up with many candidates. Also, standard account addresses often already exist in Dataverse (the Address 1 / Address 2 related rows), so you may get extra duplicates depending on your setup.

    What works better is to filter the integration table on ParentIdType = account and deal with the ParentId coupling yourself, or just make your own custom table in Dataverse for ship-to instead of reusing customeraddress. Less fighting with the standard logic and coupling stay clean.

    Hope this help, Best regards.
     Tick the checkbox below to mark the answer as verified, if it helped resolve your question.
     
    Regards
    Gregory Mavrogeorgis
     
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 621 Super User 2026 Season 1

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 445 Most Valuable Professional

#3
YUN ZHU Profile Picture

YUN ZHU 366 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans