web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Hide / Show button in the command bar based on security role

(1) ShareShare
ReportReport
Posted on by 2

In Dynamics 365 / Power Apps Model-Driven App, I created a custom button in the Command Bar using the Modern Command Designer.

 

I want the button to only be visible for users who have the "System Administrator" security role.

 

How can I control the visibility of the command bar button using a Command Library or any supported approach?

I have the same question (0)
  • Suggested answer
    ManoVerse Profile Picture
    1,143 Super User 2026 Season 1 on at
    using the Modern Command Bar, you cannot control button visibility based on a user’s security role (e.g. “Area Manager”).
    This is because Power Fx used in Modern Commanding does NOT support accessing the current user or their security roles, and functions like User() do not work at runtime for command bar visibility logic even though they may appear to return values inside the component library editor.
    This limitation is confirmed in Microsoft’s documentation for Power Fx commanding.
    Use Power Fx with commands - Power Apps | Microsoft Learn
    Supported ways to control visibility today 
     
    1) Modern Command bar, use Power Fx privilege checks permission level on table or record like below formula
     
    Show button only if user has Create permission on Accounts
    DataSourceInfo(Accounts, DataSourceInfo.CreatePermission)
    Shows button only if user has Edit privilege on the selected record:
    RecordInfo(Self.Selected.Item, RecordInfo.EditPermission)
    other permisson check available like :
    RecordInfo(Self.Selected.Item, RecordInfo.ReadPermission)
    RecordInfo(Self.Selected.Item, RecordInfo.DeletePermission)
    RecordInfo(Self.Selected.Item, RecordInfo.AssignPermission)
     
    This does not check the role explicitly but checks permissions that the user inherently has
     
    2) If you MUST check the actual Security Role, You cannot do this in Modern Commanding, because role evaluation requires current user access (unsupported).
    Instead, you must use:
    Classic Ribbon Display Rule -> Role Rule
    Classic ribbon supports role‑based visibility, which is the fully supported approach for this scenario. 

    Final take away : Modern commanding cannot perform this check based on security role name, you need to use Classic ribbon for full flexiblity on display rule. 
     
    Regards,
    Manoj
    ✅If this answer helped you, please consider marking it as Verified, it really helps others in community

     
  • Suggested answer
    Niki Patel Profile Picture
    114 on at
    In Microsoft Dynamics 365 / Power Apps Model-Driven Apps, the Modern Command Designer currently does not support direct role-based visibility for command bar buttons.
     
    To control visibility based on security roles (e.g., show only for System Administrator), you need to use a JavaScript Command Library with a visibility rule.
     
    Approach:
    1. Create a JavaScript web resource.
    2. Add a function to check if the current user has the required role.
    3. Use this function in the button’s Visibility property.
    Sample code:
    function isSystemAdmin() {
        var roles = Xrm.Utility.getGlobalContext().userSettings.roles;
        var hasRole = false;
        roles.forEach(function (role) {
            if (role.name === "System Administrator") {
                hasRole = true;
            }
        });
        return hasRole;
    }

    Then:
    • Open your command in Modern Command Designer
    • Set Visibility -> Formula / Custom rule -> Call JS function
    • Reference this function
    Note:
    Make sure the role name matches exactly (case-sensitive).
    This is the supported workaround until Microsoft adds native role-based visibility in the Modern Command Designer.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 107 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 92

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans