RE: Efficient Document Attachment for Custom Table and Page?
Hi,
You can pass the record reference to the Document Attachment page and then subscribe to the events for the document attachment to work with your table.
Action to open page:
var
DocumentAttachmentDetails: Page "Document Attachment Details";
RecRef: RecordRef;
begin
RecRef.GetTable(Rec);
DocumentAttachmentDetails.OpenForRecRef(RecRef);
DocumentAttachmentDetails.RunModal();
end;
Assuming single field Primary Key
[EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnAfterInitFieldsFromRecRef', '', true, true)]
local procedure DocumentAttachment_OnAfterInitFieldsFromRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
var
FieldRef: FieldRef;
RecNo: Code[20];
begin
case RecRef.Number of
DATABASE::"Your Table":
begin
FieldRef := RecRef.Field(10);
RecNo := FieldRef.Value;
DocumentAttachment.Validate("No.", RecNo);
end;
end;
end;
[EventSubscriber(ObjectType::Page, Page::"Document Attachment Details", 'OnAfterOpenForRecRef', '', true, true)]
local procedure DocumentAttachmentDetails_OnAfterOpenForRecRef(var RecRef: RecordRef; var DocumentAttachment: Record "Document Attachment"; var FlowFieldsEditable: Boolean)
var
FieldRef: FieldRef;
RecNo: Code[20];
begin
case RecRef.Number of
DATABASE::"Your Table":
begin
FieldRef := RecRef.Field(10);
RecNo := FieldRef.Value;
DocumentAttachment.SetRange("No.", RecNo);
FlowFieldsEditable := true;
end;
end;
end;