How to do deep inserts into a custom API in Business Central?
kuhi
Member Posts: 18
Based on this question: https://forum.mibuso.com/discussion/78013/how-to-insert-multiple-rows-in-a-business-central-api-with-a-single-call
I was testing and found the deep inserts. So I've decided to build a sample API page with a page part:
This is the page part:
I'm trying to POST this JSON with just a single header + line:
This is the response I'm getting:
So, the header is created, but the lines not...
How to deep inserts in Business Central with a custom API?
I was testing and found the deep inserts. So I've decided to build a sample API page with a page part:
page 60000 "Sales Order Inserts MIM API"
{
PageType = API;
SourceTable = "Sales Order Inserts MIM";
Caption = 'Sales Order Inserts MIM API';
EntitySetName = 'SalesOrderInserts';
EntityName = 'SalesOrderInsert';
APIPublisher = 'Kuhicop';
APIGroup = 'Kuhicop';
DelayedInsert = true;
APIVersion = 'v1.0';
layout
{
area(content)
{
repeater(Group)
{
field("BatchID"; Rec."Batch ID")
{
ApplicationArea = All;
}
field("BatchDate"; Rec."Batch Date")
{
ApplicationArea = All;
}
part(SalesOrderLines; 60001)
{
ApplicationArea = All;
SubPageLink = "Batch ID" = field("Batch ID");
}
}
}
}
}
This is the page part:
page 60001 "Sales Orders MIM"
{
ApplicationArea = All;
Caption = 'Sales Orders MIM';
SourceTable = "Sales Orders MIM";
APIGroup = 'Kuhicop';
APIPublisher = 'Kuhicop';
APIVersion = 'v1.0';
DelayedInsert = true;
EntityName = 'SalesOrder';
EntitySetName = 'SalesOrders';
PageType = API;
layout
{
area(content)
{
repeater(General)
{
field("BatchID"; Rec."Batch ID")
{
ToolTip = 'Batch ID';
}
field("DocumentNo"; Rec."Document No.")
{
ToolTip = 'Specifies the value of the Document No. field.';
}
field("LineNo"; Rec."Line No.")
{
ToolTip = 'Specifies the value of the Line No. field.';
}
}
}
}
}
I'm trying to POST this JSON with just a single header + line:
{
"BatchID": "BATCH003",
"BatchDate": "2024-05-09",
"salesOrders": [
{
"DocumentNo": "PED002",
"LineNo": 10000,
"BatchID": "BATCH003"
}
]
}
This is the response I'm getting:
{
"@odata.context": "https://api.businesscentral.dynamics.com/v2.0/{{TENANT_ID}}/{{COMPANY}}/api/Kuhicop/Kuhicop/v1.0/$metadata#companies(c6452bcb-c1b3-eb11-9b52-002248818d7e)/SalesOrderInserts/$entity",
"@odata.etag": "W/\"JzE5OzgwMDc0MzY2NzQ0NjcxOTQxOTExOzAwOyc=\"",
"BatchID": "BATCH003",
"BatchDate": "2024-05-09",
"salesOrders": []
}
So, the header is created, but the lines not...
How to deep inserts in Business Central with a custom API?
0
Answers
-
The solution is in the url of the api call. You need a reference for the subpage entity name in it. Only then it will process the nested part of the json.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 326 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
