We will learn to hide / show command bar buttons in Model Driven App using Power FX formulas. Before we start, make sure to subscribe to CRM Crate so that you can stay up to date in the field of Power Apps.
What is Microsoft’s Model-Driven commanding?
How to hide / show command buttons using Power FX formula?
Follow the below steps for dynamically changing the visibility of command buttons in the Model – Driven App.
- Open Power Apps Studio (https://make.powerapps.com/).
- Navigate to the Solutions and open the solution which contains a table / entity as per your requirement.
- Within the solution, navigate to Apps and open a Model – Driven App of your choice as shown below.
- Now select an entity / table of your choice, click on more and select “Edit Command Bar” as shown below.
- This will open a new studio window. There are different areas where command buttons are placed in a Model – Driven App as stated below.
|Main grid||Buttons placed here are displayed in the home page grid of an entity / table|
|Main form||Buttons placed here are displayed in the forms of an entity / table|
|Subgrid view||Buttons placed here are displayed in the subgrid views of an entity / table|
|Associated view||Buttons placed here are displayed in the related entity’s associated view|
- We will select the command bar customization on “Main form” as shown below.
- In the command button editor, click on “New” for adding a new button on form’s command bar. There are multiple types of buttons available as shown below. For demonstration purpose we will use a “Command” button as place it in the command bar.
- Provide a name to your button, navigate to the property “Visibility” and select visibility as “Show on conditional from formula” as shown below.
- Select the “Visibility” property and insert the Power FX formula describing the functionality for dynamically hiding & displaying the button. In our scenario, we will hide our command button when the form’s field “SRL” is less than 2 and display the command button when the “form’s field “SRL” is more than 2. Below is the Power FX formula used for achieving this functionality.
- Note: – Use the command “Self.Selected.Item” to target the currently opened record / row.
If(Self.Selected.Item.SRL < 2, false, true)
- Save & publish the changes once the configurations are completed.
Validate the functionality in the Model – Driven App
Once the command customizations are published, navigate to the Model – Driven App and verify the implementation of dynamically hiding & displaying a button as shown below.