Dynamics 365 Business Central: Displaying Sales Lines Attachments in a Factbox of Sales Order (42, Document) page

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to display Sales Lines Attachments in a Factbox of Sales Order (42, Document) page (display the Attachments Factbox of a subpage in the main page).

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

And 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 exist for the card or document. For example, on the Sales Order page:

In fact, attachments can be added not only to Sales Header but also to Sales Line. That is, additional attachments can be added to each line.

However, unlike the Sales Header, there is no Factbox to display the attachments of these lines. You must select the Line -> Related Information -> Attachments action each time. So can we add it through customization? Yes, it’s not difficult, we have discussed the following two similar requirements before.
1. Dynamics 365 Business Central: How to add a Factbox for lines/SubPage (Provider Property)

2. Dynamics 365 Business Central: Can we add Item Attributes Factbox (9110, ListPart) to Sales Order (42, Document) page??? Yes, But……

So just add it to the Factbox, which is not that difficult. But it requires some attention. Let’s see more details. When a Sales Line Attachment is created, it is associated with the following four standard fields, Table ID, No., Document Type, Line No.

We just need to add another standard Document Attachment Factbox to the main page and then link it using these four fields. Don’t forget to set the Provider Property.
Provider Property: Sets the provider for a FactBox. This property enables you to create a link from a Repeater or any other type of control to a Factbox.

Looks good.
Line 10000:

Line 20000:

Line 30000:

But there is a problem here. When you click on the number of attachments, the page that opens is empty. (There is no problem if you use standard action)

Why? This is because there is special processing in the trigger OnDrillDown of NumberOfRecords in page 1174 “Document Attachment Factbox”. Depending on the current table, the table obtained by RecRef is different. Below is some standard code:

So we also need to subscribe to the related event (Page::”Document Attachment Factbox”, OnBeforeDrillDown) and insert this part of the logic. For example,

This will solve the problem just now.

Test video:

Very simple, and other document pages can also refer to this approach. Give it a try!!!😁

Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)

pageextension 50242 SalesOrderExt extends "Sales Order"
{
    layout
    {
        addbefore(Control1903720907)
        {
            part("Sales Line Attached Documents"; "Document Attachment Factbox")
            {
                ApplicationArea = All;
                Caption = 'Sales Line Attachments';
                Provider = SalesLines;
                SubPageLink = "Table ID" = const(Database::"Sales Line"),
                              "No." = field("Document No."),
                              "Document Type" = field("Document Type"),
                              "Line No." = field("Line No.");
            }
        }
    }
}

codeunit 50242 SalesLineAttachmentHandler
{
    [EventSubscriber(ObjectType::Page, Page::"Document Attachment Factbox", OnBeforeDrillDown, '', false, false)]
    local procedure OnBeforeDrillDown(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
    var
        SalesLine: Record "Sales Line";
    begin
        case DocumentAttachment."Table ID" of
            DATABASE::"Sales Line":
                begin
                    RecRef.Open(DATABASE::"Sales Line");
                    if SalesLine.Get(DocumentAttachment."Document Type", DocumentAttachment."No.", DocumentAttachment."Line No.") then
                        RecRef.GetTable(SalesLine);
                end;
        end;
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL