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?
Microsoft has announced that the makers can create their own commands using Power Fx and the familiar Excel formula bar. This will definitely result in the lower the bar to expressing logic for developers as they no longer need to learn and debug asynchronous JavaScript code.
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.
Great stuff… too bad it doesnt work with custom Choices.
Thanks
I have created my custom button, and i know it works; however, it’s not visible through the mobile app. so, i’ve read that i need to use the powerfx script to always make it visible; however, i don’t see any options under the ‘visible’ setting other than “Show” – how do i enable the “Show on condition from formula” option so i can select it in the visible attribute??