In this post I will show how to master and create dynamic factboxes in Business Central. The data will change depending on the line of the document the user is positioned in. For this example the system will show the last item’s sales invoiced price.

The factbox

First, we need to create the factbox. It will be a ‘CardPart’ page with the “Sales Line” as the source table as we will be ‘connecting’ the factbox to the sales lines.

We will show just one field in this factbox. In the value of the field we can call any procedure we want and return the value.


The procedure will get the last invoiced price for the customer:


In order to provide the user with more information we can run the page of sales invoice lines when drilling down:


The connection


Finally, we need to connect both pages and do it so as the behaviour of the factbox is dynamic. This is done by using the ‘Provider’ and ‘SubPageLink’ properties:


The provider property let us link the lines of the source document (the repeater of the sales quote page) to our factbox.


The SubPageLink property will let us filter the lines of the sales quote (the provider) with the lines of the factbox that we indicated as the source table. It will also provide the filter to our ‘FindLastInvoicedPrice’ procedure.


If we don´t specify the provider the system will tell us that the links have to be the ones of the Sales Header as it is a page extension of the Sales Quote.

Video test:


Bonus

You can use the ‘new’ properties ‘AboutTitle’ and ‘AboutText’ to add to the standard learning tour and explain the custom parts of the document:

Code:

pageextension 50102 "Sales Quote Ext" extends "Sales Quote"
{
    layout
    {
        addfirst(factboxes)
        {
            part("Sales Quote Factbox"; "Sales Quote FactBox")
            {
                ApplicationArea = Suite;
                Provider = SalesLines;
                SubPageLink = "Document Type" = FIELD("Document Type"),
                              "Document No." = FIELD("Document No."),
                              "Line No." = FIELD("Line No.");
            }
        }
    }
}
page 50100 "Sales Quote FactBox"
{
    Caption = 'Sales Prices';
    PageType = CardPart;
    SourceTable = "Sales Line";
    AboutTitle = 'My sales prices';
    AboutText = 'Shows the last invoiced price for the selected item';

    layout
    {
        area(content)
        {
            field(LastUnitPrice; cduFuncs.FindLastInvoicedPrice(Rec."Bill-to Customer No.", Rec."No."))
            {
                ApplicationArea = all;
                Caption = 'Last Unit Price';

                trigger OnDrillDown()
                var
                    SalesInvLine: Record "Sales Invoice Line";
                begin
                    SalesInvLine.SetRange("Bill-to Customer No.", Rec."Bill-to Customer No.");
                    SalesInvLine.SetRange("No.", Rec."No.");
                    if SalesInvLine.FindFirst() then
                        Page.RunModal(Page::"Posted Sales Invoice Lines", SalesInvLine);
                end;
            }
        }
    }

    var
        cduFuncs: Codeunit "Functions";
}
codeunit 50100 "Functions"
{
    internal procedure FindLastInvoicedPrice(BilltoCustomerNo: Code[20]; ItemNo: Code[20]): Decimal
    var
        SalesInvLine: Record "Sales Invoice Line";
    begin
        SalesInvLine.SetRange("Bill-to Customer No.", BilltoCustomerNo);
        SalesInvLine.SetRange("No.", ItemNo);
        if SalesInvLine.FindLast() then
            exit(SalesInvLine."Unit Price");
    end;
}

Hope you find it useful.

Master Factboxes In Business Central

Post navigation


2 thoughts on “Master Factboxes In Business Central

  1. Very Interesting. Thanks for Sharing.
    I’m trying to create a factbox to show all the sales Prices (table 7002) when an item is selected in the sales invoice.
    Do you have any idea how to go around it please ?

    1. Hi, thanks! Yes, it´s the same idea. Only thing is you need a repeater instead for that. Your factbox page as a repeater with the fields you need (similar to a list page but it´s just a CardPart).

Leave a Reply

Your email address will not be published. Required fields are marked *