Dynamics 365 Business Central: How to show or hide a value for the user based on an expression (HideValue Property)

Dynamics 365 Business Central

Hi, Readers.
In my previous post, we discussed how to dynamically hide or show fields in Business Central. And yesterday I received an interesting question, is there any easy way to show or hide a value on the page, such as Balance (LCY), Sales (LCY) on the Customer list, Credit Limit (LCY), Total Sales on the Customer Card. For some reason, they don’t want to hide the field, only want to hide the value of the field.

So, today I would like to talk about how to show or hide a value for the user based on an expression.

This time we need to use the HideValue Property.
HideValue Property: Sets whether to show or hide a value for the user based on an expression.

Applies to: Page Label and Page Field

Property Values: True if the value is hidden; otherwise, false. The default is false.

First, let’s add a setting field in User Setup. For example, “Allow View Financial Data”; Boolean. If the user is set to True, the user can view the financial data on the customer. If False, the system hides the financial data by default.

Source Code:

tableextension 50113 ZYUserSetupExt extends "User Setup"
{
    fields
    {
        field(50100; "Allow View Financial Data"; Boolean)
        {
            Caption = 'Allow View Financial Data';
            DataClassification = CustomerContent;
        }
    }
}

pageextension 50113 ZYUserSetupPageExt extends "User Setup"
{
    layout
    {
        addafter("Allow Posting To")
        {
            field("Allow View Financial Data"; Rec."Allow View Financial Data")
            {
                ApplicationArea = All;
            }
        }
    }
}

Then add logic to Customer List page.

Test Video:

Source Code: Show or hide a value for the user | GitHub

pageextension 50125 ZYCustomerList extends "Customer List"
{
    layout
    {
        modify("Balance (LCY)")
        {
            HideValue = IsPermissionToView;
        }

        modify("Balance Due (LCY)")
        {
            HideValue = IsPermissionToView;
        }

        modify("Sales (LCY)")
        {
            HideValue = IsPermissionToView;
        }

        modify("Payments (LCY)")
        {
            HideValue = IsPermissionToView;
        }
    }

    trigger OnOpenPage()
    begin
        IsPermissionToView := false;
        IsPermissionToView := IsHavePermissionToView();
    end;

    var
        [InDataSet]
        IsPermissionToView: Boolean;

    local procedure IsHavePermissionToView(): Boolean
    var
        UserSetup: Record "User Setup";
    begin
        if UserSetup.Get(UserId) then begin
            if UserSetup."Allow View Financial Data" then
                exit(false)
            else
                exit(true);
        end else begin
            exit(true);
        end;
    end;
}

The field value is shown in the UI as an empty space. If the field happens to also define a drilldown control, the space may show as underlined. This is intended for UI clarity, not security.

Please note that although the user does not have the permission to view the value, by default, the user can click Drill down to view the details.
For example:

And the underlying value will still be visible to the user in certain cases such as page inspector, table viewer, etc.
PS: You can control access to Page Inspection Details. For more details: https://yzhums.com/7087/

But the value will not be visible to the user in Open in Excel.

Note:
1. HideValue is useful for choosing to hide a value based on some conditions; such as the value of another field.

2. Accessing the same table from other pages, from OData APIs or other integrating apps may reveal the value. These must each implement their own mechanisms to hide the value under the same conditions. For example, the Excel AddIn, Power Apps, Power BI, and cards displayed by the Teams app do not respect this property.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

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