Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Attaching Documents to Custom Tables

(1) ShareShare
ReportReport
Posted on by 24
I have created a custom table and would like to attach documents to it.  I am using the code below.
But it when I attach the document it doesn't attach to the table and record, but rather just to table 0
 
IDLine No.Document TypeNo.Table IDAttachmentFile ExtensionFile Type
10Quote 0PO_CustomLayoutdocxWord
20Quote 0PO_CustomLayout2docxWord
 
        area(factboxes)
        {
            part(/Attached Documents/; /Document Attachment Factbox/)
            {
                ApplicationArea = All;
                Caption = 'Project Task Attachments';
                SubPageLink = /Table ID/ = const(50108),
                /No./ = field(/Task Name/);
            }
            systempart(Control1900383207; Links)
            {
                ApplicationArea = RecordLinks;
            }
            systempart(Control1905767507; Notes)
            {
                ApplicationArea = Notes;
 
 
  • Community member Profile Picture
    24 on at
    Attaching Documents to Custom Tables
    My key is below
     
            key(key1; "Task Name")
  • Gerardo Rentería García Profile Picture
    17,772 Most Valuable Professional on at
  • Suggested answer
    Mohana Yadav Profile Picture
    60,222 Super User 2025 Season 1 on at
    Attaching Documents to Custom Tables
    What is the Primary Key of Project Task table?
    Is this filter correct?
    /No./ = field(/Task Name/);
     
    Please check at the bottom of the blog about handling multiple fields in Primary key scenario if project task has multiple fields in primary key.
  • Community member Profile Picture
    24 on at
    Attaching Documents to Custom Tables
    Thanks Mohana,
     
    I added the codeunit please see below, but it didn't work.
    My custom table is Project Task
     
    codeunit 50154 DocumentAttachment
    {
        [EventSubscriber(ObjectType::Page, Page::"Document Attachment Factbox", 'OnBeforeDrillDown', '', false, false)]
     
        local procedure OnBeforeDrillDown(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
        var
            ProjectTask: Record "Project Task";
        begin
            case DocumentAttachment."Table ID" of
                DATABASE::"Project Task":
                    begin
                        RecRef.Open(DATABASE::"Project Task");
                        if ProjectTask.Get(DocumentAttachment."No.") then
                            RecRef.GetTable(ProjectTask);
                    end;
     
            end;
        end;
     
        [EventSubscriber(ObjectType::Page, Page::"Document Attachment Details", 'OnAfterOpenForRecRef', '', false, false)]
        local procedure OnAfterOpenForRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
        var
            FieldRef: FieldRef;
            RecNo: Code[20];
        begin
            case RecRef.Number of
                DATABASE::"Project Task":
                    begin
                        FieldRef := RecRef.Field(1);
                        RecNo := FieldRef.Value;
                        DocumentAttachment.SetRange("No.", RecNo);
                    end;
            end;
        end;
     
        [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::"Project Task":
                    begin
                        FieldRef := RecRef.Field(1);
                        RecNo := FieldRef.Value;
                        DocumentAttachment.Validate("No.", RecNo);
                    end;
            end;
        end;
    }
  • Suggested answer
    Mohana Yadav Profile Picture
    60,222 Super User 2025 Season 1 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans