To hide a button in Dynamics 365 (D365) model-driven apps, the most straightforward and recommended approach is to use the modern Power Apps Command Bar Editor. This involves adding a Display Rule to the button's command, specifically a Value Rule with the "Invert Result" property set to True
.
This guide will walk you through the primary method and explore other valuable techniques for managing button visibility.
Understanding Command Visibility in Dynamics 365
In D365 model-driven apps, buttons on forms, grids, and subgrids are controlled by underlying "Commands." These commands dictate not only what action the button performs but also its visibility and enabled state through Display Rules and Enable Rules. By manipulating these rules, you gain precise control over when and where a button appears to users.
Method 1: Hiding Buttons Using the Power Apps Command Bar Editor (Recommended)
The Power Apps Command Bar Editor offers a modern, low-code interface within the Power Apps portal to customize the command bar. This method is highly efficient for hiding existing or custom buttons.
Step-by-Step Guide
-
Access Power Apps Maker Portal:
- Navigate to the Power Apps maker portal.
- Select the correct environment where your D365 app resides.
-
Open Your Model-Driven App:
- Go to Apps in the left navigation pane.
- Select your desired model-driven app and click Edit (or select ... > Edit).
-
Select the Table and Command Bar Location:
- Within the App Designer, choose the Page (table) where the button you want to hide is located.
- Select the specific command bar you wish to edit (e.g., "Main form," "Main grid," "Subgrid view"). Click ... > Edit command bar.
-
Locate the Button Command:
- In the Command Bar Editor, identify the button you want to hide.
- Select the button, then look for its associated "Command" in the properties pane on the right.
-
Add a Display Rule:
- With the command selected, click on + Add under the "Display Rules" section.
- Choose Rule Type as Value Rule.
-
Configure the Value Rule:
- When configuring the Value Rule, you'll set its condition. For simple, unconditional hiding:
- You can create a basic condition that always evaluates to
true
(e.g., using a custom JavaScript function that simply returnstrue
, or a specific environment variable value that is always present). - Crucially, ensure you set Invert Result = True. This reverses the outcome of your Value Rule. If your rule typically makes the button visible (evaluates to true), inverting the result will effectively hide it.
- You can create a basic condition that always evaluates to
- For conditional hiding, set your
Value Rule
condition to evaluate totrue
when you want the button to be hidden, and then setInvert Result = False
. Alternatively, set the rule to evaluatetrue
when it should be visible andInvert Result = True
to hide it. For simple "hide this button," a Value Rule that is always true withInvert Result = True
is effective.
- When configuring the Value Rule, you'll set its condition. For simple, unconditional hiding:
-
Save and Publish:
- After configuring the Display Rule, click Save in the Command Bar Editor.
- Then, click Publish to apply your changes to the live app.
Method 2: Conditional Hiding with JavaScript
For more complex and dynamic hiding scenarios, especially when visibility depends on multiple conditions, user interactions, or data not easily accessed by Value Rules, JavaScript can be used.
- Custom JavaScript Function: Write a JavaScript web resource containing a function that returns
true
(to make the button visible) orfalse
(to hide the button) based on your custom logic. - Attach to Display Rule (Custom Rule): In the Command Bar Editor, instead of a Value Rule, add a Display Rule and select Custom Rule.
- Specify your JavaScript web resource library.
- Enter the name of your JavaScript function.
- You can also pass parameters to your function if needed.
- Benefit: This method offers ultimate flexibility for sophisticated conditional logic.
Method 3: Using Security Roles for Button Visibility
While not directly configuring a "hide" rule on the button itself, managing security roles can implicitly hide buttons by removing access to the underlying actions they perform. If a user lacks the necessary privilege to perform an action (e.g., "Delete" a record), the associated button might not even appear in the UI.
- Privilege Checks: Many out-of-the-box buttons are linked to specific security privileges (e.g., Create, Read, Write, Delete privileges on a table).
- Custom Privileges: For custom buttons that perform specific custom actions, you can create custom security privileges and associate them with your command. Users without this privilege will not see the button.
- Note: This method is about managing permissions and access, which often translates to UI visibility, rather than just UI customization.
Method 4: Legacy Approach - Ribbon Workbench
For older Dynamics 365 versions, or for very specific and advanced ribbon customizations, the Ribbon Workbench (an external tool part of XrmToolBox) is still a powerful option.
- Hide Action: Within Ribbon Workbench, you can select a button and use the "Hide" action to completely remove it from the ribbon.
- Enable/Display Rules (XML): You can also define granular enable and display rules using XML directly within Ribbon Workbench, offering fine-grained control over button states.
- Consideration: This method requires more technical expertise and direct manipulation of the RibbonDiff XML.
Choosing the Right Method
The best method depends on your specific requirements:
Method | Complexity | Use Case | Modern Tool |
---|---|---|---|
Command Bar Editor (Value Rule w/ Invert) | Low | Simple, unconditional, or basic conditional hiding | Yes |
Command Bar Editor (JS Custom Rule) | Medium | Complex, dynamic conditional hiding | Yes |
Security Roles | Low-Medium | Permission-based access control | N/A |
Ribbon Workbench (Legacy/Advanced XML) | High | Advanced, legacy, or highly specific customizations | No |
Best Practices for Button Hiding
- Start with the Command Bar Editor: Always prioritize the Power Apps Command Bar Editor for button customizations due to its low-code nature and ease of maintenance.
- Test Thoroughly: After making any changes to button visibility, thoroughly test your application in various scenarios and with different user roles to ensure the buttons hide/show as expected.
- Document Your Changes: Keep a record of why specific buttons were hidden and the rules applied. This helps with future maintenance and troubleshooting.
- Consider User Experience: Ensure that hiding buttons makes the user interface cleaner and more intuitive, rather than confusing users about missing functionality.