Dynamics 365 Business Central: How to add Attachments, Links, Notes Factbox to any pages

Dynamics 365 Business Central

Hi, Readers.
Yesterday, we discussed how to calculate and display the Average, Count, Sum of the selected lines in FactBox. For more details: https://yzhums.com/11138/
Today I would like to continue the discussion about FactBox.

As you might know, in the FactBox on most cards and documents, you can attach files, add links, and write notes. For links and notes, you can also do this on the list page by first selecting the related line.

To view or change any of these attached information types, you must first open the Attachments tab in the FactBox. The number behind the tab title indicates how many attached files, links, or notes exist for the card or document.

So for pages that don’t include Attachments, Links, Notes Factbox as standard, or for custom new pages, can we add them ourselves?
For example: Payment Terms

Yes, Let’s try it together.

First you can find the codes of the three Factboxes on the page 21 “Customer Card”.
Document Attachment Factbox is a Common factbox.
Links and Notes Factbox are system factboxes.

Create a page extension to “Payment Terms”, then add three FactBoxes to the page.

pageextension 50111 PaymentTermsExt extends "Payment Terms"
{
    layout
    {
        addfirst(FactBoxes)
        {
            part("Attached Documents"; "Document Attachment Factbox")
            {
                ApplicationArea = All;
                Caption = 'Attachments';
                SubPageLink = "Table ID" = CONST(3),
                              "No." = FIELD(Code);
            }
            systempart(PyamentTermsLinks; Links)
            {
                ApplicationArea = RecordLinks;
            }
            systempart(PyamentTermsNotes; Notes)
            {
                ApplicationArea = Notes;
            }
        }
    }
}

Note: 3 is the table number of Payment Terms, and Code is the primary key of Payment Terms.

If you publish the extension now, the Links and Notes Factboxes are already working properly.

But for Document Attachment Factbox, after adding attachments, you will find that Table ID and No. are not recorded in the table Document Attachment (1173).

Although you can now upload an attachment, that attachment does not point to this record correctly.

Customer Card:

So there are two more steps to do for Document Attachment Factbox.

1. Specifies the open table.

2. Specifies the field associated with the table.

Code:

codeunit 50101 DocumentAttachment
{
    [EventSubscriber(ObjectType::Page, Page::"Document Attachment Factbox", 'OnBeforeDrillDown', '', false, false)]
    local procedure OnBeforeDrillDown(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
    var
        PaymentTerms: Record "Payment Terms";
    begin
        case DocumentAttachment."Table ID" of
            DATABASE::"Payment Terms":
                begin
                    RecRef.Open(DATABASE::"Payment Terms");
                    if PaymentTerms.Get(DocumentAttachment."No.") then
                        RecRef.GetTable(PaymentTerms);
                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::"Payment Terms":
                begin
                    FieldRef := RecRef.Field(1);
                    RecNo := FieldRef.Value;
                    DocumentAttachment.SetRange("No.", RecNo);
                end;
        end;
    end;

}

Ok, publish extension again and test.

Test Video:

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました