Dynamics 365 Business Central: How to note the records that the user has selected on the Subpage/Lines (Page.SetSelectionFilter in part)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share another mini tip about Business Central, how to note the records that the user has selected on the Subpage/Lines (Page.SetSelectionFilter in part)

Page.SetSelectionFilter(var Record) is a very commonly used method, which can get the value currently selected by the user.

Page.SetSelectionFilter(var Record): Notes the records that the user has selected on the page, marks those records in the table specified, and sets the filter to “marked only”.

Here is a simple example.

Very simple.

PS: Dynamics 365 Business Central: About the automatic filtering problem after using Page.SetSelectionFilter Method

Here is a small question. When the list is not the main page but a part page, can this method also be used to get the selected data?

Yes, it’s simple too.

There are two cases:

1. This operation is performed on the main page

First we need to know the name of the subpage (part), SalesLines.

Then we can get the value currently selected by the user through Currpage.{Subpage name}.Page.SetSelectionFilter(). For example,
CurrPage.SalesLines.Page.SetSelectionFilter(Salesline);

A simple test:

Test code:

pageextension 50114 SalesOrderExt extends "Sales Order"
{
    actions
    {
        addafter("Archive Document")
        {
            action(Count)
            {
                ApplicationArea = All;
                Caption = 'Count selected lines';
                Promoted = true;
                PromotedCategory = Process;
                Image = Calculate;
                ToolTip = 'This action counts the number of sales orders.';

                trigger OnAction()
                var
                    Salesline: Record "Sales Line";
                begin
                    Salesline.Reset();
                    CurrPage.SalesLines.Page.SetSelectionFilter(Salesline);
                    Message('Number of selected lines: %1', Salesline.Count());
                end;
            }
        }
    }
}

2. This operation is performed on the subpage (part)

This case is no different from the normal usage, except that the action is added directly to the subpage (part) instead of the main page.

Test code:

pageextension 50115 SalesOrderSubformExt extends "Sales Order Subform"
{
    actions
    {
        addafter("Select Nonstoc&k Items")
        {
            action(Count)
            {
                ApplicationArea = All;
                Caption = 'Count selected lines';
                Image = Calculate;
                ToolTip = 'This action counts the number of sales orders.';

                trigger OnAction()
                var
                    Salesline: Record "Sales Line";
                begin
                    Salesline.Reset();
                    CurrPage.SetSelectionFilter(Salesline);
                    Message('Number of selected lines: %1', Salesline.Count());
                end;
            }
        }
    }
}

Very simple, give it a try!!!😁

PS: Dynamics 365 Business Central: How to use Page.SetSelectionFilter Method in temporary records

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL