Dynamics 365 Business Central: Adding a FactBox with a list of attachments

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about an interesting topic, how to simply add a FactBox with a list of attachments in Business Central.
This is a question I saw in the Dynamics 365 Community today. More details: Display table of attachments in Document Attachment Factbox

A FactBox is the area that is located on the right-most side of a page and it is divided into one or more parts that are arranged vertically. This area is used to display content including other pages, charts, and system parts such as Notes, and Links. Typically, you can use a FactBox to display information that is related to an item on the main content page. For example, on a page that shows a sales order list, you can use a FactBox to show sell-to customer sales history for a selected sales order in the list as shown below. More details: Adding a FactBox to a Page

On most list pages, cards, and documents, you can attach files on the Attachments tab of the FactBox pane. The number in the tab title indicates how many attached files.

To view an attached file:

  1. On the FactBox, open the Attachments tab.
  2. Choose the value behind the Documents field, such as “1”.
  3. On the Attached Documents page, choose the Download action or click Attachment Name.
  4. Open the downloaded file.

Therefore, as mentioned above, in the Facetbox pane on many pages, only the number of the attachment is displayed, and the content is not directly displayed. If you need to download, you need to click on the number to open the Attached Documents page first, and then you can download it. Is there any simple way to see the attachment list directly in the Factbox pane? And can it be downloaded directly?
Yes, it’s not difficult and only requires a few lines of code. Let’s see more details.

In this example, I directly extend the page below, but you can also create a new page.
Document Attachment Factbox (1174, CardPart)

First, add a new repeater control below the Documents field. Due to limited space, I only added two fields, File Name and File Type.

Looks good.

As for the code for clicking File Name and then downloading, you can refer to the standard code.
page 1173 “Document Attachment Details”:
trigger OnDrillDown():

Or action(Preview):

For example,

Great.

Test video:

Very simple, give it a try!!!😁

Test code: Github

pageextension 50111 DocumentAttachmentFactboxExt extends "Document Attachment Factbox"
{
    layout
    {
        addlast(Control2)
        {
            repeater(Attatchments)
            {
                field("File Name"; Rec."File Name")
                {
                    ApplicationArea = All;
                    Caption = 'Attachment';

                    trigger OnDrillDown()
                    begin
                        if Rec.HasContent() then
                            Rec.Export(true);
                    end;
                }
                field("File Type"; Rec."File Type")
                {
                    ApplicationArea = All;
                    Caption = 'File Type';
                }
            }
        }
    }
}

Update 2024.09.09: Business Central 2024 wave 2 (BC25): Use drag and drop on file upload dialog to attach multiple files (New Documents Factbox)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL