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

Community site session details

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

How do i hide/show Edit button command based on a criteria

(0) ShareShare
ReportReport
Posted on by 15
Hi All,
I'm new to this and have a model driven app i need to customise.
I would like to disable the Edit command bar if the  user is in a specific user role (Dataverse Teams and a role assigned to it) and the field status is marked as complete.

When i tried opened the edit button  in using the power apps designer it was all greyed out and marked a read only.
I think my option is to use javascript and webresources.
I also noticed alot of people are talking about using Ribbon Workbench but not sure if i can use such logic in it

To have a javascript do this where would be best way to start e.g looking for the right function to call to get the roles to compare or how to see the field names

Thanks in advance
I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    10,782 Moderator on at
    How do i hide/show Edit button command based on a criteria

    Hi,

     

    To conditionally show or hide the Edit button in a model-driven app based on user roles and field values, you’ll need to use Ribbon Workbench along with JavaScript. Here's a general approach to get started:

     

    1. Use Ribbon Workbench: This tool allows you to customize command bar buttons. You can define display rules and enable rules based on JavaScript functions.


    2. Create a JavaScript Web Resource: Write a function that checks:

       

      • If the current user has a specific security role.

      • If the field status is marked as complete.
       

      Example snippet:

       

       

      function shouldShowEditButton(formContext) {
          var status = formContext.getAttribute("status").getValue();
          var userRoles = Xrm.Utility.getGlobalContext().userSettings.roles;
      
          var hasRole = userRoles.some(function(role) {
              return role.name === "YourRoleName";
          });
      
          return !(hasRole && status === "Complete");
      }
      

       


    3. Attach the Function in Ribbon Workbench: Use this function in a Display Rule or Enable Rule for the Edit button.


    4. Publish and Test: After publishing the changes, test the behavior in your app to ensure the button visibility aligns with your criteria.



    5.  
     

    This setup gives you flexibility and control over UI behavior based on business logic.

     

    Please verify if this helps you move forward.

     

    Thanks and best regards,\
    Daniele\
    Note: This response was prepared with support from Copilot to ensure clarity and completeness.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 1,786

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 1,132 Most Valuable Professional

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 351 Super User 2025 Season 2

Product updates

Dynamics 365 release plans