Skip to content

[Bug]: Cannot attach files to Posted Sales Shipment — GetRefTable has no case for Sales Shipment Header #10181

Description

Describe the issue

Uploading a file from the Attachments FactBox on a Posted Sales Shipment fails with "The record is not open."

Listing existing attachments works, and Attach as PDF works. Only the manual upload path fails.

Steps to reproduce

  1. Post a sales order so that a posted sales shipment exists.
  2. Open the Posted Sales Shipment page (130).
  3. In the FactBox pane, open the Attachments tab and expand Documents.
  4. Choose Upload files (or drag a file onto the FactBox) and select any file.

Expected: the file is attached, creating a Document Attachment record with Table ID = 110 and No. = the shipment number, as it already works on Posted Sales Invoice.

Actual: error "The record is not open."

Same result on Posted Sales Shipments (142). Base Application 28.3.52162.53239.

Root cause

DocAttachmentListFactbox.Page.al checks GetRefTable but continues unconditionally when it fails:

trigger OnAction(files: List of [FileUpload])
var
    DocumentAttachment: Record "Document Attachment";
    DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
    RecRef: RecordRef;
begin
    if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then
        OnAfterGetRecRefFail(Rec, RecRef);
    DocumentAttachment.SaveAttachment(files, RecRef);
    CurrPage.Update();
end;

Document Attachment Mgmt.GetRefTable (src/Layers/W1/BaseApp/Foundation/Attachment/DocumentAttachmentMgmt.Codeunit.al) has no case for Database::"Sales Shipment Header", nor for Database::"Return Receipt Header". Its case statement covers only Customer, Vendor, Item, Employee, Fixed Asset, Resource, Job, Sales Header, Sales Invoice Header, Sales Cr.Memo Header, Purchase Header, Purch. Inv. Header, Purch. Cr. Memo Hdr., VAT Report Header and Opportunity.

With no matching case the RecordRef is never opened, and the procedure ends with:

OnAfterGetRefTable(RecRef, DocumentAttachment);
exit(RecRef.Number > 0);

so it returns false. The page raises OnAfterGetRecRefFail, but there is no guard afterwards, so with no subscriber execution falls through to SaveAttachment with an unopened RecordRef. That reaches the first statement of InsertAttachment in DocumentAttachment.Table.al:

local procedure InsertAttachment(DocStream: InStream; RecRef: RecordRef; FileName: Text; AllowDuplicateFileName: Boolean)
var
    IsHandled: Boolean;
begin
    if not RecRef.Find() then
        Error(RecordRefNotFoundErr);

RecRef.Find() on an unopened RecordRef raises "The record is not open.", which matches the call stack below.

The table looks only partially wired: TableHasNumberFieldPrimayKey in the same codeunit does have a case for it:

Database::"Sales Shipment Header":
    begin
        FieldNo := 3;
        exit(true);
    end;

and likewise for Database::"Return Receipt Header".

Still missing on main as of 2026-08-12.

Call stack:

"Document Attachment"(Table 1173).InsertAttachment line 4 - Base Application by Microsoft version 28.3.52162.53239
"Document Attachment"(Table 1173).SaveAttachmentFromStream line 7 - Base Application by Microsoft version 28.3.52162.53239
"Document Attachment"(Table 1173).SaveAttachment line 9 - Base Application by Microsoft version 28.3.52162.53239
"Document Attachment"(Table 1173).SaveAttachment line 3 - Base Application by Microsoft version 28.3.52162.53239
"Doc. Attachment List Factbox"(Page 1178)."AttachmentsUpload - OnAction"(Trigger) line 8 - Base Application by Microsoft version 28.3.52162.53239

Scope

  • Affects manual upload from the Attachments FactBox on Posted Sales Shipment (130) and Posted Sales Shipments (142).
  • Return Receipt Header has the identical profile — present in TableHasNumberFieldPrimayKey, absent from GetRefTable, and given the Attachment part by the same release — so Posted Return Receipt (6660) and Posted Return Receipts (6662) are expected to fail the same way.
  • Attach as PDF on the same pages is not affected. PostedSalesShipment.Page.al calls Rec.PrintToDocumentAttachment(SalesShipmentHeader) with the real record, so it never needs to rebuild the parent from Table ID + No. and never goes through GetRefTable. This is likely why the gap shipped unnoticed.
  • Listing and opening existing attachments is not affected — the part's SubPageLink is correct ("Table ID" = const(Database::"Sales Shipment Header"), "No." = field("No.")).
  • Posted Sales Invoice, Posted Sales Cr. Memo and the other tables already handled by GetRefTable are not affected.

Suggested fix

Add the two missing cases to GetRefTable, mirroring the existing Sales Invoice Header pattern:

Database::"Sales Shipment Header":
    begin
        RecRef.Open(Database::"Sales Shipment Header");
        if SalesShipmentHeader.Get(DocumentAttachment."No.") then
            RecRef.GetTable(SalesShipmentHeader);
    end;
Database::"Return Receipt Header":
    begin
        RecRef.Open(Database::"Return Receipt Header");
        if ReturnReceiptHeader.Get(DocumentAttachment."No.") then
            RecRef.GetTable(ReturnReceiptHeader);
    end;

plus the two local record variables.

Secondary, suggested as a separate commit: stop in AttachmentsUpload when the RecordRef is still not open after OnAfterGetRecRefFail, so an unsupported table produces a meaningful error instead of "The record is not open.":

if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then begin
    OnAfterGetRecRefFail(Rec, RecRef);
    if RecRef.Number = 0 then
        Error(UnsupportedTableErr, Rec."Table ID");
end;

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM area

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions