Hi Experts,
I create a deep insert for in my extension to use one request to create sales order or update sales order.
Now I encounter one problem, I can create sales order with lines successfully.
but when I use request to update the sales order, only the sales header fields are updated, but the lines are updated.
Is anyone can shed me some lights on how to solve this problem? Is it possible to use one request update all lines in the sales order?
Below is the Pages I create and the request I used to update the sales Order.
Thanks
Sales Header
page 70203543 TRCSalesOrderHeaderAPI
{
APIVersion = 'v1.0';
Caption = 'salesOrders', Locked = true;
ChangeTrackingAllowed = true;
DelayedInsert = true;
EntityName = 'salesOrder';
EntitySetName = 'salesOrders';
ODataKeyFields = "No.";
PageType = API;
APIPublisher = 'XXXXX';
APIGroup = 'XXX';
SourceTable = "Sales Header";
Extensible = false;
Permissions = tabledata "Sales Header" = rimd;
layout
{
area(content)
{
repeater(Group)
{
field(id; Id)
{
ApplicationArea = All;
}
field("documentType"; "Document Type")
{
ApplicationArea = All;
}
field("number"; "No.")
{
ApplicationArea = All;
}
field("orderDate"; "Order Date")
{ ApplicationArea = All; }
.
.
.
part(salesOrderLines; 70203542)
{
ApplicationArea = All;
Caption = 'Lines', Locked = true;
EntityName = 'salesOrderLine';
EntitySetName = 'salesOrderLines';
SubPageLink = "Document No." = FIELD("No."), "Document Type" = FIELD("Document Type");
}
}
}
}
trigger OnInsertRecord(BelowxRec: Boolean): Boolean
begin
Insert(true);
Modify(true);
exit(false);
end;
trigger OnDeleteRecord(): Boolean
begin
Delete(true);
end;
trigger OnModifyRecord(): Boolean
var
SO: Record "Sales Header";
begin
end;
}
Sales Lines
page 70203542 TRCSalesOrderLinesAPI
{
Caption = 'salesOrderLines';
PageType = ListPart;
DelayedInsert = true;
SourceTable = "Sales Line";
ODataKeyFields = "Document No.";
AutoSplitKey = true;
Permissions = tabledata "Sales Line" = rimd;
layout
{
area(Content)
{
repeater(General)
{
field("documentType"; "Document Type")
{
ApplicationArea = All;
}
field("documentNumber"; "Document No.")
{
ApplicationArea = All;
}
field("lineNumber"; "Line No.")
{
ApplicationArea = All;
}
field("sellToCustomerNumber"; "Sell-to Customer No.")
{
ApplicationArea = All;
}
field("type"; Type)
{
ApplicationArea = All;
}
field("number"; "No.")
{
ApplicationArea = All;
}
field("quantity"; Quantity)
{
ApplicationArea = All;
}
field("unitPrice"; "Unit Price")
{
ApplicationArea = All;
}
.
.
.
}
}
}
trigger OnInsertRecord(BelowxRec: Boolean): Boolean
begin
Insert(true);
Modify(true);
exit(false);
end;
trigger OnDeleteRecord(): Boolean
begin
Delete(true);
end;
trigger OnModifyRecord(): Boolean
var
Lines: Record "Sales Line";
begin
Lines.Reset();
Lines.SetRange("Document No.", Rec."Document No.");
Lines.SetRange("Document Type", Rec."Document Type");
Lines.SetRange("Line No.", Rec."Line No.");
if (Lines.FindSet()) then begin
Lines."Unit Price" := rec."Unit Price";
end;
Lines.Modify();
end;
var
InventoryType: Option;
trigger OnAfterGetCurrRecord()
var
item: Record Item;
begin
item.Reset();
if item.Get(rec."No.") then
InventoryType := item.Type;
end;
}
Request:
Patch:bc110:7048/.../salesOrders('EDI1002')
{
"orderDate": "2020-08-20",
"salesOrderLines": [
{
"lineNumber": 10000,
"type": "Item",
"number": "1896-S",
"quantity": 3,
"unitPrice": 6
}
]