Dynamics 365 Business Central: Controlling access to My Settings (Role, Company, Work date…)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to discuss how to control access to My Settings.
On the My Settings page, you can see and change basic settings for Business Central. The changes that you make will only affect your workspace, not the workspaces of other users.
For example, Role Center, Company, Work Date, etc.

I have encountered some requests that clients do not want end-users to change information such as Company, Role, Work Day, etc on the My Settings page.

As you may know, My Settings is a Standard Dialog page in Business Central. So there are two ways to do this control.
My Settings (9176, StandardDialog)

Using Permission Set (No customization)

The following are all the page permissions that need to be used in the My Settings page.

So we can easily create a new permission set to manage detailed permissions.
For example:
1. Create a new permission set by copying D365 BASIC.

2. Choose Permissions.

3. Delete Page 0. (All objects of type page)

4. Choose New to add new permission.

Let’s see it in detail.

My Settings:
My Settings (9176, StandardDialog)

If the user does not have Execute permission on Page My Settings, they will not be able to access My Settings.

You do not have the following permissions on Page My Settings: Execute.

Role:
Available Roles (9178, List)

User Personalization Card (9172, Card)

Same as the above.

You do not have the following permissions on Page Available Roles: Execute.

Note: If the user does not have the execute permission of User Personalization Card (9172, Card), an error will be displayed when changing the role. But the role will be saved successfully. Therefore, it is recommended to add this permission to the user by default.

You do not have the following permissions on Page User Personalization Card: Execute.

Company:
Allowed Companies (9177, List)

Same as the above.

You do not have the following permissions on Page Allowed Companies: Execute.

Region and Language:

Windows Languages (535, List)

Same as the above.

You do not have the following permissions on Page Windows Languages: Execute.

Time Zone:
Time Zones (9200, List)

Same as the above.

You do not have the following permissions on Page Time Zones: Execute.

Notifications:
My Notifications (1518, List)

Same as the above.

You do not have the following permissions on Page My Notifications: Execute.

In conclusion, using Permission Set, you can manage access control to all items about My Settings, except Work Day.
For Work Day, if you just want to control the posting date, please use Allow Posting From and Allow Posting To field on the User Setup page.

Using extensions (Customization)

Permission control can be made very flexible by using the extension. The following is just a solution for reference only.

1. Add new setup fields in the User Setup table.

Source Code:

tableextension 50113 UserSetupExt extends "User Setup"
{
    fields
    {
        field(50100; "Allow Open My Settings"; Boolean)
        {
            Caption = 'Allow Open My Settings';
            DataClassification = CustomerContent;
        }
        field(50101; "Allow Change Role"; Boolean)
        {
            Caption = 'Allow Change Role';
            DataClassification = CustomerContent;
        }
        field(50102; "Allow Change Company"; Boolean)
        {
            Caption = 'Allow Change Company';
            DataClassification = CustomerContent;
        }
        field(50103; "Allow Change Work Day"; Boolean)
        {
            Caption = 'Allow Change Work Day';
            DataClassification = CustomerContent;
        }
    }
}

2. Display the added fields on User Setup page.

Source Code:

pageextension 50113 UserSetupPageExt extends "User Setup"
{
    layout
    {
        addafter("Allow Posting To")
        {
            field("Allow viewing all orders"; Rec."Allow Open My Settings")
            {
                ApplicationArea = All;
            }
            field("Allow Change Role"; Rec."Allow Change Role")
            {
                ApplicationArea = All;
            }
            field("Allow Change Company"; Rec."Allow Change Company")
            {
                ApplicationArea = All;
            }
            field("Allow Change Work Day"; Rec."Allow Change Work Day")
            {
                ApplicationArea = All;
            }

        }
    }
}

User Setup Page:

3. Use pageextension to extend the My Settings page, then add the following restrictions.
If the user does not have permission to open the My Settings page, an error will be reported.
If the user does not have permission for the items, the items is not displayed by default.

Source Code:

pageextension 50100 CustomerListExt extends "My Settings"
{
    layout
    {
        modify(UserRoleCenter)
        {
            Visible = AllowChangeRole;
        }
        modify(Company)
        {
            Visible = AllowChangeCompanyName;
        }
        modify(NewWorkdate)
        {
            Visible = AllowChangeWorkDay;
        }
    }


    trigger OnOpenPage();
    var
        UserSetup: Record "User Setup";
        NoPermission: Label 'You do not have permission to open the My Settings page. Please contact your administrator';
    begin
        AllowChangeRole := false;
        AllowChangeCompanyName := false;
        AllowChangeWorkDay := false;
        if UserSetup.Get(UserId) then
            if UserSetup."Allow Open My Settings" then begin
                AllowChangeRole := UserSetup."Allow Change Role";
                AllowChangeCompanyName := UserSetup."Allow Change Company";
                AllowChangeWorkDay := UserSetup."Allow Change Work Day";
                exit;
            end;
        Error(NoPermission);
    end;

    var
        AllowChangeRole: Boolean;
        AllowChangeCompanyName: Boolean;
        AllowChangeWorkDay: Boolean;

}

For example:
Allow Open My Settings on User Setup page is false.

Error:

Allow Open My Settings and Allow Change Role on User Setup page are true, but Allow Change Company and Allow Change Work Day are false.

My Settings page can be opened, but Company and Work Day will be hidden.

Test Video:

END

Hope this will help.

Thanks for reading.

ZHU

コメント

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