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

Add Attachment To Custom Table Question

(2) ShareShare
ReportReport
Posted on by 131

I have a table with three fields that define the primary key: Type (Option: Sales, Purchases), Document Type (Option: Invoice, Credit Memo, Order, Guarantee, Contract, Loan), and No (Code [20])..

I want to add functionality to my table so that I can attach files using the standard Document Attachment table.

The attachment factbox page has been changed from Document Attachment Factbox to Doc. Attachment List Factbox, but now I don’t know how to reference my table as a RecordRef

On which event can I retrieve information about my table?

 

I tried following the approach shown on http://www.yzhums.com/11177/, but it doesn’t work very well.

I have the same question (0)
  • Suggested answer
    Haris Korac Profile Picture
    131 on at
    Add Attachment To Custom Table Question
    @Pallavi Phade 
    Thank you very much for your answer, but that not solved my issue. This is my code:
        [EventSubscriber(ObjectType::Page, Page::"Doc. Attachment List Factbox", 'OnAfterGetRecRefFail', '', false, false)]
        local procedure OnAfterGetRecRefFail(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
        var
            DocumentManagementLoc: Record "Document Management_VSL";
        begin
            case DocumentAttachment."Table ID" of
                DATABASE::"Document Management_VSL":
                    begin
                        RecRef.Open(DATABASE::"Document Management_VSL");
                        if DocumentManagementLoc.Get(DocumentAttachment.Type_VSL, DocumentAttachment."Document Type", DocumentAttachment."No.") then
                            RecRef.GetTable(DocumentManagementLoc);
     
                    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];
            TypeDM: Option "Sales","Purchase";
            DocumentTypeDM: Option "Invoice","Credit Memo","Contract","Guarantee","Loan","Order";
            DocumentTypeEnum: Enum "Attachment Document Type";
     
        begin
            // Message('2');
     
            case RecRef.Number of
                DATABASE::"Document Management_VSL":
                    begin
                        FieldRef := RecRef.Field(3);
                        RecNo := FieldRef.Value;
     
                        //DocumentAttachment.SetRange("No.", RecNo);
     
                        FieldRef := RecRef.Field(1);
                        TypeDM := FieldRef.Value;
     
                       // DocumentAttachment.SetRange(Type_VSL, TypeDM);
     
                        // FieldRef := RecRef.Field(2);
                        // DocumentTypeDM := FieldRef.Value;
     
                        FieldRef := RecRef.Field(199);
                        DocumentTypeEnum := FieldRef.Value;
                        // Message('2 ' + Format(DocumentTypeDM));
                        DocumentAttachment.SetRange("Document Type", DocumentTypeEnum);
                        DocumentAttachment.SetRange("Table ID", RecRef.Number);
                        DocumentAttachment.SetRange(Type_VSL, TypeDM);
                        DocumentAttachment.SetRange("No.",RecNo);
     
                        //Message(Format(TypeDM));
                    end;
            end;
        end;


     
        [EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnAfterInitFieldsFromRecRef', '', false, false)]
        local procedure OnAfterInitFieldsFromRecRefDocMgt(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
        var
            FieldRef: FieldRef;
            // FieldRefType: FieldRef;
            // FieldRefDocumentType: FieldRef;
            RecNo: Code[20];
            TypeDM: Option "Sales","Purchase";
            DocumentTypeDM: Option "Invoice","Credit Memo","Contract","Guarantee","Loan","Order";
            DocumentTypeEnum: Enum "Attachment Document Type";
        begin
            // Message('3');
            //Message(Format(RecRef.RecordId));
            case RecRef.Number of
                DATABASE::"Document Management_VSL":
                    begin
                        FieldRef := RecRef.Field(3);
                        RecNo := FieldRef.Value;
                        DocumentAttachment.Validate("No.", RecNo);
     
                        FieldRef := RecRef.Field(1);
                        TypeDM := FieldRef.Value;
                        DocumentAttachment.Validate(Type_VSL, TypeDM);
     
                        FieldRef := RecRef.Field(2);
                        DocumentTypeDM := FieldRef.Value;
                        DocumentAttachment.Validate(DocManDocType_VSL, DocumentTypeDM);
     
                        FieldRef := RecRef.Field(199);
                        DocumentTypeEnum := FieldRef.Value;
     
                        DocumentAttachment.Validate("Document Type", DocumentTypeEnum);
     
                    end;
            end;
        end;
  • Suggested answer
    Pallavi Phade Profile Picture
    1,841 on at
    Add Attachment To Custom Table Question
    Namaste @Haris Korac
     
    This issue is sovled in below Community Thread . It might help you . If not please let me know 
     
     
     
    Regards
    Pallavi Phade 

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
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,885

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,405

#3
Sumit Singh Profile Picture

Sumit Singh 2,837

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans