📄 Summary: Integrating Doc. Attachment List Factbox for Custom Tables/Pages
🔍 Objective:
Replace the deprecated Document Attachment FactBox with the modern Doc. Attachment List Factbox, and ensure it functions with custom tables and pages by handling record binding correctly.
🛠️ Required Steps & Code
✅ 1. Add Doc. Attachment List Factbox to Your Page
Target: Add to your custom list or card page.
al
area(FactBoxes)
{
part(Attachments; "Doc. Attachment List Factbox")
{
ApplicationArea = All;
SubPageLink = "Table ID" = const(Database::"Your Custom Table"), "No." = field("Your Primary Key Field");
}
}
✅ 2. Handle Record Binding (EventSubscriber #1)
Event: OnAfterGetRecRefFail
Purpose: Tells the system how to bind your custom record to the attachment record.
al
[EventSubscriber(ObjectType::Page, Page::"Doc. Attachment List Factbox", OnAfterGetRecRefFail, '', false, false)]
local procedure OnAfterGetRecRefFail(var Sender: Page "Doc. Attachment List Factbox"; DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
var
CustomHeader: Record "Your Custom Table";
begin
case DocumentAttachment."Table ID" of
DATABASE::"Your Custom Table":
begin
RecRef.Open(DATABASE::"Your Custom Table");
if CustomHeader.Get(DocumentAttachment."No.") then
RecRef.GetTable(CustomHeader);
end;
end;
end;
✅ 3. Handle Reverse Mapping (EventSubscriber #2)
Event: OnAfterInitFieldsFromRecRef
Purpose: Ensures the Document Attachment record is populated from your custom record.
al
[EventSubscriber(ObjectType::Table, Database::"Document Attachment", OnAfterInitFieldsFromRecRef, '', false, false)]
local procedure OnAfterInitFieldsFromRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
var
FieldRef: FieldRef;
RecNo: Code[20];
begin
case RecRef.Number of
DATABASE::"Your Custom Table":
begin
FieldRef := RecRef.Field(1); // Assumes PK is in field 1
RecNo := FieldRef.Value;
DocumentAttachment.Validate("No.", RecNo);
end;
end;
end;
✅ Final Output
📎 Attachments can be added directly from the custom page UI.
📂 Multiple files are supported.
📋 Attachments are visible on both Card and List pages.
⬇️ Files can be downloaded as expected.