We want to build AL API page to POST Return Sales order lines.
We succesfully POST Return Sales Order using API Page for Source table = "Sales header" with document type = "Return order"
But then we try to do POST call with correct Document No(which exists in MBC after first POST call to Sales header API page) and Document Type = "Return order" and receive following error:
{"code":"Internal_InvalidTableRelation","message":"The field Document No. of table Sales Line contains a value (1029) that cannot be found in the related table (Sales Header). CorrelationId: 11a32c7c-6f5e-44da-9f2f-59deeaab9cd3."}}
Our AL Page looks foloowing:
page 50129 ApiPageSalesHeadersLines
{
PageType = API;
Caption = 'ApiPageSalesHeadersLines';
APIPublisher = 'Tests';
APIGroup = 'TestApp';
APIVersion = 'v1.0';
EntityName = 'SalesHeaderLine';
EntitySetName = 'SalesHeaderLines';
SourceTable = "Sales Line";
DelayedInsert = true;
InsertAllowed = true;
ModifyAllowed = true;
layout
{
area(Content)
{
repeater(GroupName)
{
field(number; "Document No.")
{
Caption = 'documentNumber';
}
field(documentType; "Document Type")
{
Caption = 'documentType';
}
field("itemCode"; "No.")
{
Caption = 'itemCode';
}
field(description; Description)
{
Caption = 'description';
}
field("unitOfMeasure"; "Unit of Measure")
{
Caption = 'unitOfMeasure';
}
field(quantity; Quantity)
{
Caption = 'quantity';
}
field("unitPrice"; "Unit Price")
{
Caption = 'unitPrice';
}
field("quantityShipped"; "Quantity Shipped")
{
Caption = 'quantityShipped';
}
field("shipmentDate"; "Shipment Date")
{
Caption = 'shipmentDate';
}
field("lineDiscountPercent"; "Line Discount %")
{
Caption = 'lineDiscountPercent';
}
field("vatPercent"; "VAT %")
{
Caption = 'vatPercent';
}
field("type"; Type)
{
Caption = 'type';
}
field("amount"; Amount)
{
Caption = 'amount';
}
field("sellToCustomerNo"; "Sell-to Customer No.")
{
Caption = 'sellToCustomerNo';
}
}
}
}
}
We did POST request to route:
/v2.0/Production/api/Tests/TestApp/v1.0/companies(b35e5010-ded7-ea11-96a6-000d3aac12ef)/SalesHeaderLines
Can, please, someone explain what we need to do for succesfull sales line POST?
Thanks in advance!