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

[Error] customer already has a contact business relation with contact

(0) ShareShare
ReportReport
Posted on by 358

I created two tables Called Catergory and Sector that has two table fields each Code and Description. On the customer table, I extended to have Code of Category and Code of Sector. I then added those two fields on the Customer Card page and when I insert the data I get the following error.

customer already has a contact business relation with contact

Here is my code;

table 50131 "mySectortable"
{
    DataClassification = ToBeClassified;
    LookupPageId = "Customer Sector";

    fields
    {
        field(50000; "Code"; Code[20])
        {
            DataClassification = ToBeClassified;

        }
        field(50001; "Description"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
    }

    keys
    {
        key(PK; Code)
        {
            Clustered = true;
        }
    }

    var
        myInt: Integer;

    trigger OnInsert()
    begin

    end;

    trigger OnModify()
    begin

    end;

    trigger OnDelete()
    begin

    end;

    trigger OnRename()
    begin

    end;

}

table 50133 "myCategorytable"
{
    DataClassification = ToBeClassified;
    LookupPageID = "Customer Category";

    fields
    {
        field(50000; "Code"; Code[20])
        {
            DataClassification = ToBeClassified;

        }
        field(50001; "Description"; Text[50])
        {
            DataClassification = ToBeClassified;
        }
    }

    keys
    {
        key(PK; Code)
        {
            Clustered = true;
        }
    }

    var
        myInt: Integer;

    trigger OnInsert()
    begin

    end;

    trigger OnModify()
    begin

    end;

    trigger OnDelete()
    begin

    end;

    trigger OnRename()
    begin

    end;

}

page 50136 "Customer Category"
{
    PageType = List;
    Editable = true;
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = myCategorytable;


    layout
    {
        area(Content)
        {
            repeater(Category)
            {
                field(Code; Code)
                {
                    ApplicationArea = All;
                    NotBlank = true;
                    ShowMandatory = true;

                }
                field(Description; Description)
                {
                    ApplicationArea = All;
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            action(ActionName)
            {
                ApplicationArea = All;

                trigger OnAction()
                begin

                end;
            }
        }
    }

    var
        myInt: Integer;
}

page 50135 "Customer Sector"
{
    PageType = List;
    Editable = true;
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = mySectortable;

    layout
    {
        area(Content)
        {
            repeater(Sector)
            {
                field(Code; Code)
                {
                    ApplicationArea = All;
                    NotBlank = true;
                    ShowMandatory = true;

                }
                field(Description; Description)
                {
                    ApplicationArea = All;
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            action(ActionName)
            {
                ApplicationArea = All;

                trigger OnAction()
                begin

                end;
            }
        }
    }

    var
        myInt: Integer;
}

tableextension 50121 "Customer Table Ext" extends Customer
{
    fields
    {
        // Add changes to table fields here
        field(50000; "Customer Category"; Code[20])
        {
            TableRelation = myCategorytable;
        }
        field(50001; "Customer Sector"; Code[20])
        {
            TableRelation = mySectortable;
        }
        field(50002; "Location"; Code[10])
        {
            TableRelation = Location;
        }
    }

    var
        myInt: Integer;
}

pageextension 50122 "Customer Card Ext" extends "Customer Card"
{
    layout
    {
        // Add changes to page layout here
        addafter("Disable Search by Name")
        {
            field("Category"; recCategory.Code)
            {
                ApplicationArea = All;
                TableRelation = Category_DSSS;
                trigger OnValidate()
                var
                    recCustomer: Record Customer;
                begin
                    recCustomer.SetFilter("No.", Rec."No.");
                    IF recCustomer.FindFirst() then begin
                        recCustomer."Customer Category" := rec."Customer Category";
                        recCustomer.Insert(true);
                    end;
                   
                end;
            }
            field("Sector"; recSector.Code)
            {
                ApplicationArea = All;
                TableRelation = Sector_DSSS;
                trigger OnValidate()
                var
                    recCustomer: Record Customer;
                begin
                    recCustomer.SetFilter("No.", Rec."No.");
                    IF recCustomer.FindFirst() then begin
                        recCustomer."Customer Sector" := rec."Customer Sector";
                        recCustomer.Insert(true);
                    end;
                    
                end;
            }
        }

        addafter("Language Code")
        {
            field(Location; Location)
            {
                ApplicationArea = All;
                TableRelation = Location;
                trigger OnValidate()
                var
                    recCustomer: Record Customer;
                begin
                    IF recCustomer.FindFirst() then begin
                        recCustomer.Location := rec.Location;
                        recCustomer.Insert(true);
                    end;

                    // CurrPage.SaveRecord();
                end;
            }
        }
    }

    actions
    {
        // Add changes to page actions here
    }

    var
        recCategory: Record Category_DSSS;
        recSector: Record Sector_DSSS;
}

I have the same question (0)
  • Suggested answer
    Olister Rumao Profile Picture
    4,009 on at

    Hi Mesam,

    If I'm not wrong you are using Customer.Insert but the record is already inserted by default.

    You need to used Customer.Modify.

    This will update your customer record with the relevant data.

    Secondly when you are using Table relation, after you have selected the field with appropriate table valued from the drop down you don't need to add any special code to deal with insert or update.

    Automatically it gets selected on the record itself.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,870 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,138 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 915 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans