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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

The entity with a name = ' ' with namemapping = 'Logical' was not found in the MetadataCache.

(3) ShareShare
ReportReport
Posted on by 311

Hello,

When I am trying to integrate the standard table "Ship-to Address" table from BusinessCentral with CustomerAddress table from Sales I am getting below error when I am doing full sync.

Error description:

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=18992154, MinActiveRowVersion=18992154, MetadataInstanceId=4219632, LastUpdated=2022-02-21 09:52:59.373

Included code for review 

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;
            //CRMId := 'LEWES ROAD';
            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(SystemId), CDSCustomerAddress.FieldNo(ParentId), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo(Code), CDSCustomerAddress.FieldNo(name), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo(Address), CDSCustomerAddress.FieldNo(Line1), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo("Address 2"), CDSCustomerAddress.FieldNo(Line2), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo(City), CDSCustomerAddress.FieldNo(City), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo(County), CDSCustomerAddress.FieldNo(StateOrProvince), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo("Post Code"), CDSCustomerAddress.FieldNo(PostalCode), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        InsertIntegrationFieldMapping('customeraddress', ShipToAddress.FieldNo("Country/Region Code"), CDSCustomerAddress.FieldNo(Country), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);

    end;

}

I have the same question (1)
  • Suggested answer
    Andy Sather Profile Picture
    on at

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

  • HHalim Profile Picture
    10 on at

    Hi Vinayak,

    I just come across the same issue.

    Just wondering, if you found any solution for this issue ? Thanks

  • CU29080825-0 Profile Picture
    24 on at
    I am aslo getting same issue in my report like the entity name doesnot exist.Please specify an existing enitytname 
    the entity with a name=cxnsdu_caserequest with namemapping='logical' was not found in the MetadataCache.LazyDynamicMetadatacache with 10362215 and timestamp 103612215
  • Suggested answer
    Nimsara Jayathilaka. Profile Picture
    4,836 on at
    Hi
     
    Looking at your code and the error message, I can identify the main issue causing this sync error. The problem is in the LookupCDSCustomerAddress procedure where you're setting the CRM ID incorrectly
     
    Try Below Code
    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";
            CDSCustomerAddressList: Page "CRM Customeraddress List";
        begin
            if not IsNullGuid(CRMId) then begin
                if CDSCustomerAddress.Get(CRMId) then
                    CDSCustomerAddressList.SetRecord(CDSCustomerAddress);
                if not IsNullGuid(SavedCRMId) then
                    if OriginalCDSCustomerAddress.Get(SavedCRMId) then
                        CDSCustomerAddressList.SetCurrentlyCoupledCRMCustomerAddress(OriginalCDSCustomerAddress);
            end;
    
            CDSCustomerAddress.SetView(IntTableFilter);
            CDSCustomerAddressList.SetTableView(CDSCustomerAddress);
            CDSCustomerAddressList.LookupMode(true);
            if CDSCustomerAddressList.RunModal = ACTION::LookupOK then begin
                CDSCustomerAddressList.GetRecord(CDSCustomerAddress);
                // Fixed: Use the correct primary key field
                CRMId := CDSCustomerAddress.CustomerAddressId;
                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('CUSTOMERADDRESS', 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
            // Fixed: Use CustomerAddressId as the UID field instead of Name
            InsertIntegrationTableMapping(
                IntegrationTableMapping, 'CUSTOMERADDRESS',
                DATABASE::"Ship-to Address", DATABASE::"CRM Customeraddress", 
                CDSCustomerAddress.FieldNo(CustomerAddressId), CDSCustomerAddress.FieldNo(ModifiedOn), 
                '', '', true);
    
            // Field mappings - Fixed mapping name to match the one defined above
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo(SystemId), CDSCustomerAddress.FieldNo(ParentId), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo(Code), CDSCustomerAddress.FieldNo(name), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo(Name), CDSCustomerAddress.FieldNo(Name), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo(Address), CDSCustomerAddress.FieldNo(Line1), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo("Address 2"), CDSCustomerAddress.FieldNo(Line2), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo(City), CDSCustomerAddress.FieldNo(City), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo(County), CDSCustomerAddress.FieldNo(StateOrProvince), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo("Post Code"), CDSCustomerAddress.FieldNo(PostalCode), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
            InsertIntegrationFieldMapping('CUSTOMERADDRESS', ShipToAddress.FieldNo("Country/Region Code"), CDSCustomerAddress.FieldNo(Country), IntegrationFieldMapping.Direction::ToIntegrationTable, '', true, false);
        end;
    }
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,785

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,007 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 948 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans