Dynamics 365 Business Central: The page mode that the page was opened in (Editable of the page)

Dynamics 365 Business Central

Hi, Readers.
Today, I would like to discuss the page mode that the page was opened in.
As you may know, when we open a page in Business Central, it is usually in an editable state.
For example Customer Card.
And any changes are saved automatically and do not require confirmation.
So some clients may ask whether it is possible to open the page as non-editable by default.

First of all, It is recommend to create a new permission set to manage whether a user can modify or not. And you can also use the monitoring changes feature in Business Central, such as Change Logs, Field Monitoring, and Data audit system fields. These do not require customization.

But if you still want to change the page mode that the page was opened in, it is also very simple, you can use Editable Property.

There is a note in the MS Docs:

When using CurrPage.Editable, the Editable property also reflects the page mode that the page was opened in. This applies to Edit, Create, and Delete modes, but not to View mode. If the page is editable, then CurrPage.Editable will return false.

So create a new page extension for the page. For example, Customer Card.
And add code in trigger OnOpenPage().

pageextension 50133 CustomerCardExt extends "Customer Card"
{
    trigger OnOpenPage();
    begin
        CurrPage.Editable(false);
    end;
}

OK, Let’s see the results.
Test video:
1. When you open a record, the page changes to non-editable mode. You cannot switch to edit mode.
2. When you view a record, the page is in non-editable mode, but you can switch to edit mode.
3. When you create a new record, the record can be created, but you can not modify it. Because the page is in non-editable mode.
4. You can delete the record.

PS:
If you don’t want it to work for all users, you can easily add a setting field in User Setup.
For example:

tableextension 50113 UserSetupExt extends "User Setup"
{
    fields
    {
        field(50100; "Allow Edit Mode"; Boolean)
        {
            Caption = 'Allow Edit Mode';
            DataClassification = CustomerContent;
        }
    }
}

pageextension 50113 UserSetupPageExt extends "User Setup"
{
    layout
    {
        addafter("Allow Posting To")
        {
            field("Allow Edit Mode"; Rec."Allow Edit Mode")
            {
                ApplicationArea = All;
            }
        }
    }
}
pageextension 50133 CustomerCardExt extends "Customer Card"
{
    trigger OnOpenPage();
    var
        UserSetup: Record "User Setup";
    begin
        if UserSetup.Get(UserId) then
            if UserSetup."Allow Edit Mode" then
                exit;
        CurrPage.Editable(false);
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました