So I have an AL project that’s installed as a BC 365 v19.5 on-prem extension. The Codeunit procedure that creates a new Purchase Header works fine. I can see the new entry in the Purchase Orders list. But I have a separate Codeunit procedure that needs to add a new Purchase Line to that Purchase Header. Looking at the code I appear to be cross-referencing the linked field(s). Which is primarily the PurchLine.“Document No.” => PurchHeader.“No.”, correct?
Here is the 404 error response body I get when trying to add the new Purchase Line:
{“error”:{“code”:“Internal_InvalidTableRelation”,“message”:“The field Document No. of table Purchase Line contains a value (PO100029) that cannot be found in the related table (Purchase Header). CorrelationId: fb67003b-60bb-4bd6-a990-db6a58529a84.”}}
Any suggestions on how to resolve this? I can clearly see the Document No. in the Purchase Orders list. I am properly setting the PurchLine.“Line No.” value, the PurchLine.“Document Type” value, the PurchLine.“Type” value, etc. I’ll include a partial code snippet below.
PurchaseHdr.SetRange("No.", PoNum);
if PurchaseHdr.FindFirst() then begin
PurchaseLnLu.SetRange("Document No.", PoNum);
if PurchaseLnLu.FindLast() then
LineNo := PurchaseLnLu."Line No." + 10000
else
LineNo := 10000;
PurchaseLn.Init();
PurchaseLn.Validate("Line No.", LineNo);
PurchaseLn.Validate("Document No.", PurchaseHdr."No.");
PurchaseLn.Validate("Document Type", PurchaseHdr."Document Type");
PurchaseLn.Validate("Buy-from Vendor No.", PurchaseHdr."Buy-from Vendor No.");
PurchaseLn.Validate("Pay-to Vendor No.", PurchaseHdr."Pay-to Vendor No.");
PurchaseLn.Validate("Currency Code", PurchaseHdr."Currency Code");
PurchaseLn.Validate("Type", PurchaseLnType::Item);
...