web
You’re offline. This is a read only version of the page.
close
Skip to main content
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;
 
 
I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    60,977 Super User 2025 Season 2 on at
    Attaching Documents to Custom Tables
  • 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,977 Super User 2025 Season 2 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.
  • Gerardo Rentería García Profile Picture
    23,590 Most Valuable Professional on at
    Attaching Documents to Custom Tables
  • Community member Profile Picture
    24 on at
    Attaching Documents to Custom Tables
    My key is below
     
            key(key1; "Task Name")

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sumit Singh Profile Picture

Sumit Singh 2,204

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,933

#3
YUN ZHU Profile Picture

YUN ZHU 1,885 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans