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

Announcements

No record found.

Community site session details

Community site session details

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

Additional OnInsertRecord is trigger when doing deep insert using API

(1) ShareShare
ReportReport
Posted on by 2
 
I have 2 tables lets call TableHeader and TableLine. In TableHeader, one field had TableRelation define. When i try to do POST request with deep insert, i notice additional OnInsertRecord is trigger in TableLine. This cause additional row being insert.  If i remove the table relation in TableHeader, then it work as expected. Does anyone know why tablerelation cause additional trigger to the OnInsertRecord?
 
table 1 "TableHeader"
{
    DataClassification = CustomerContent;

    fields
    {
        field(1; "Entry No."; Integer)
        {
            AutoIncrement = true;
        }
        field(10; "Message No."; Text)
        {
            TableRelation = "TableMessage"."Message No";
        }
}

table 2 "TableLine"
{
    DataClassification = CustomerContent;

    fields
    {
        field(1; "Entry No."; Integer)
        {
            AutoIncrement = true;
        }
        field(10; "Message No."; Text)
        {
            TableRelation = "TableMessage"."Message No";
        }
		field(11; "Description"; Text)
        {
        }
}

page 1 "Header"
{
    PageType = API;
    Extensible = false;
    APIPublisher = 'publisher';
    APIGroup = 'group';
    APIVersion = 'v1.0';

    EntityName = 'header';
    EntitySetName = 'headers';
    SourceTable = "TableHeader";

    DelayedInsert = true;
    DeleteAllowed = false;
    ModifyAllowed = false;
    ODataKeyFields = SystemId;
	
	layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(id; Rec.SystemId)
                {
                    Caption = 'Id';
                    Editable = false;
                }

                field("messageNumber"; Rec."Message No.")
                {
                }

                part(lines; "Line")
                {
                    EntityName = 'line';
                    EntitySetName = 'lines';
                    SubPageLink = "Message No." = field("Message No.");

                }
            }
        }
    }
}

page 2 "Line"
{
    PageType = API;
    Extensible = false;
    APIPublisher = 'publisher';
    APIGroup = 'group';
    APIVersion = 'v1.0';

    EntityName = 'line';
    EntitySetName = 'lines';
    SourceTable = "TableLine";

    DelayedInsert = true;
    DeleteAllowed = false;
    ModifyAllowed = false;
    ODataKeyFields = SystemId;
	
	layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(id; Rec.SystemId)
                {
                    Caption = 'Id';
                    Editable = false;
                }

                field("messageNumber"; Rec."Message No.")
                {
                }

                field("description"; Rec."Description")
                {
                }
            }
        }
    }
}

JSON 

{
    "messageNumber": "Message 1",
    "lines":   [{
                                    "Description": "Description 1"
                                },
                                {
                                    "Description": "Description 2"
                                }]
}
 
 


 
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    21,573 Super User 2026 Season 1 on at
    I think the TableRelation causes the system to maintain referential integrity between related tables. When you use a deep insert with a TableRelation, the system tries to automatically manage the relationships between the parent and child records, which can lead to unexpected behavior.
     
  • Suggested answer
    YUN ZHU Profile Picture
    97,897 Super User 2026 Season 1 on at
    Hi, hope the following can give you some hints.
    Tips & Tricks for Creating Custom APIs
     
    Thanks.
    ZHU

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 2,140 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,009 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 960 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans