Dynamics 365 Business Central: How to bulk edit user roles/profiles (Customization)

Dynamics 365 Business Central

Hi, Readers.
Last week we briefly discussed how to define default Role Center (Profile) for users in Business Central.

Then I received an interesting feedback. They had imported users, and the number of users is relatively large. They were looking for an easy way to edit the user roles in bulk.

Role:
The role, or profile, describes the user’s function in the company, such as Sales Manager, Bookkeeper, or Purchasing Agent. The profile then determines the user’s role center, the home page that users will see when they sign in. The profile does not impact access rights to functionality in Business Central.

As an administrator, you can configure user settings in Business Central, similar to how individual users can manage their own preferences in the My Settings page.

The User Settings list shows the current settings for each user. To view or edit individual users, choose the View or Edit action.

My Settings page:

But unfortunately, Microsoft does not provide the function of bulk editing, only one by one.

So, how to do it? The first reaction is whether the configuration package can be used to update the background table.

table 2000000073 “User Personalization”:

This is a system table, so this way doesn’t work……

Validation Results
You cannot use system table 2000000073 in the package.

Next I investigated the standard code for editing Roles to see if it was customizable.

UserSettingsImpl.EditProfileID(Rec);

internal procedure EditProfileID(var UserPersonalization: Record “User Personalization”)

 procedure PopulateProfiles(var TempAllProfile: Record “All Profile” temporary)

Note: The Access Property of codeunit 9175 “User Settings Impl.” is Internal. The object can be accessed only by code in the same extension, but not from another extension.

Okay, let’s copy the standard code and modify it a bit to meet our needs.

local procedure PopulateProfiles:

New action:

Test Video: Looks like it’s working well.😁

Souce Code:

pageextension 50111 ZYUserSettingsListExt extends "User Settings List"
{
    actions
    {
        addfirst(Processing)
        {
            action(BulkEditRoles)
            {
                Caption = 'Bulk Edit User Roles';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                PromotedOnly = true;
                Image = UpdateDescription;

                trigger OnAction()
                var
                    UserPersonalization: Record "User Personalization";
                    TempAllProfile: Record "All Profile" temporary;
                begin
                    UserPersonalization.Reset();
                    CurrPage.SetSelectionFilter(UserPersonalization);
                    if UserPersonalization.FindSet() then begin
                        PopulateProfiles(TempAllProfile);
                        if Page.RunModal(Page::Roles, TempAllProfile) = Action::LookupOK then begin
                            repeat
                                UserPersonalization."Profile ID" := TempAllProfile."Profile ID";
                                UserPersonalization."App ID" := TempAllProfile."App ID";
                                UserPersonalization.Scope := TempAllProfile.Scope;
                                UserPersonalization.CalcFields("Role");
                                UserPersonalization.Modify();
                            until UserPersonalization.Next() = 0;
                            CurrPage.Update();
                        end;
                    end;
                end;
            }
        }
    }

    var
        DescriptionFilterTxt: Label 'Navigation menu only.';
        UserCreatedAppNameTxt: Label '(User-created)';


    local procedure PopulateProfiles(var TempAllProfile: Record "All Profile" temporary)
    var
        AllProfile: Record "All Profile";
    begin
        TempAllProfile.Reset();
        TempAllProfile.DeleteAll();
        AllProfile.SetRange(Enabled, true);
        AllProfile.SetFilter(Description, '<> %1', DescriptionFilterTxt);
        if AllProfile.FindSet() then
            repeat
                TempAllProfile := AllProfile;
                if IsNullGuid(TempAllProfile."App ID") then
                    TempAllProfile."App Name" := UserCreatedAppNameTxt;
                TempAllProfile.Insert();
            until AllProfile.Next() = 0;
    end;
}

PS:
User settings has nothing to do with a user’s personalization, such as lightweight changes to the user interface. User settings determine the predefined settings for each user in various aspects of the way the application presents itself to the user.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

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