Dynamics 365 Business Central: How to disable ‘Go to Next/Previous document’ action on Card page and Document page

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to disable ‘Go to Next/Previous document’ action on Card page and Document page in Business Central.
As you know, in the card page and document page of Business Central, we can go directly to the previous or next record. For example,
Customer Card (21, Card):

Sales Order (42, Document):

Go to previous document of the same type:

Go to the next document of the same type:

Test video:

I recently received a question about whether there is a way to disable this action. So in this post, I would like to briefly talk about this.

First of all, this is a standard behavior integrated in the platform of Card page and Document page in Business Central. There is no need to add additional code. It only needs to be that the page type is Card or Document.
Let’s see a simple example. I created a very simple list page and card page. The source table is Customer (18).
List page:

Source code:

page 50105 "New Customer List"
{
    ApplicationArea = All;
    Caption = 'New Customer List';
    PageType = List;
    SourceTable = Customer;
    UsageCategory = Lists;
    CardPageId = "New Customer Card";

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field("No."; Rec."No.")
                {
                    ToolTip = 'Specifies the number of the customer. The field is either filled automatically from a defined number series, or you enter the number manually because you have enabled manual number entry in the number-series setup.';
                }
                field(Name; Rec.Name)
                {
                    ToolTip = 'Specifies the customer''s name.';
                }
                field("Phone No."; Rec."Phone No.")
                {
                    ToolTip = 'Specifies the customer''s telephone number.';
                }
                field("Currency Code"; Rec."Currency Code")
                {
                    ToolTip = 'Specifies the default currency for the customer.';
                }
                field("Language Code"; Rec."Language Code")
                {
                    ToolTip = 'Specifies the language to be used on printouts for this customer.';
                }
            }
        }
    }
}

Card page:

Source code:

page 50104 "New Customer Card"
{
    ApplicationArea = All;
    Caption = 'New Customer Card';
    PageType = Card;
    SourceTable = Customer;

    layout
    {
        area(content)
        {
            group(General)
            {
                Caption = 'General';

                field("No."; Rec."No.")
                {
                    ToolTip = 'Specifies the number of the customer. The field is either filled automatically from a defined number series, or you enter the number manually because you have enabled manual number entry in the number-series setup.';
                }
                field(Name; Rec.Name)
                {
                    ToolTip = 'Specifies the customer''s name.';
                }
                field("Phone No."; Rec."Phone No.")
                {
                    ToolTip = 'Specifies the customer''s telephone number.';
                }
                field("Currency Code"; Rec."Currency Code")
                {
                    ToolTip = 'Specifies the default currency for the customer.';
                }
                field("Language Code"; Rec."Language Code")
                {
                    ToolTip = 'Specifies the language to be used on printouts for this customer.';
                }
            }
        }
    }
}

If we want to disable ‘Go to Next/Previous document’ action, we can use OnNextRecord (Page) Trigger.

OnNextRecord (Page) Trigger: Determines the next record to be displayed.

Remarks: This trigger is executed in place of the default next record behavior. If an error occurs in the trigger code, the page is closed.
For example, add the following code to the Card page.

When the user clicks Go to previous document or Go to the next document, an error will be prompted and the page will automatically close.

Test video:

Okay, does that end this topic? No, there is another problem, The OnNextRecord (Page) Trigger cannot be used in page extension. So as of now (BC23) it can only be used on pages and request pages.

More details: Page Extension Triggers

So is there any method for standard Card page and Document? Yes, here’s a little trick.

This time we can use Record.FilterGroup Method.

Record.FilterGroup Method: Gets or sets the filter group that is applied to a table.
Dynamics 365 Business Central uses the following filter groups internally. (-1..7)

NumberNameDescription
-1Cross-columnUsed to support the cross-column search.
0StdThe default group where filters are placed when no other group has been selected explicitly. This group is used for filters that can be set from the filter dialogs by the end user.
1GlobalUsed for filters that apply globally to the entire application.
2FormUsed for the filtering actions that result from the following:
– SetTableView Method (XMLport)SetTableView Method (Page)
– SourceTableView Property
– DataItemTableView Property.
3ExecUsed for the filtering actions that result from the following:
– SubPageView Property
– RunPageView Property
4LinkUsed for the filtering actions that result from the following:
– DataItemLink Property (Reports)
– SubPageLink Property
5TempNot currently used.
6SecurityUsed for applying security filters for user permissions.
7FactboxesUsed for clearing the state of factboxes.

We can achieve the above requirement by using the following features.

A filter set in a group different from filter group 0 cannot be changed by a user that uses a filter dialog to set a filter. If, for example, a filter has been set on customer numbers 1000 to 2000 in group 4, then the user can set a filter that delimits this selection further, but cannot widen it to include customer numbers outside the range 1000 to 2000.

More details: Dynamics 365 Business Central: How to make some filters mandatory on the list page (users can not change or remove)

So, in order not to affect standard functions, we can set a group greater than 7. Just like adding default filters to the list page, we can add this logic in OnOpenPage() trigger on the Card page or Document page. (Although this code seems to make no sense😑, it locks the user into viewing only the current record on the current page.)

Let’s see the effect. When the user clicks Go to previous document or Go to the next document, the following information will be displayed, because it is not an error, the page will not automatically close.

There are no further pages in this direction.

Test video:

Of course, this method can also be used in new custom pages.

Great, give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL