[Bug]: Cannot attach files to Posted Sales Shipment — GetRefTable has no case for Sales Shipment Header
@PredragMaricic is already working on this.
Since Aug 24, 2026.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
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
- Post a sales order so that a posted sales shipment exists.
- Open the Posted Sales Shipment page (
130). - In the FactBox pane, open the Attachments tab and expand Documents.
- 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 Headerhas the identical profile — present inTableHasNumberFieldPrimayKey, absent fromGetRefTable, 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.alcallsRec.PrintToDocumentAttachment(SalesShipmentHeader)with the real record, so it never needs to rebuild the parent fromTable ID+No.and never goes throughGetRefTable. This is likely why the gap shipped unnoticed. - Listing and opening existing attachments is not affected — the part's
SubPageLinkis 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
GetRefTableare 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
-
The Attachment part was added to these pages by the 2026 release wave 1 feature Send posted sales shipments and return receipts by email (general availability 1 April 2026).
GetRefTablewas not extended at the same time. -
I will provide a fix for a bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.