CRM Crate

Hide / Show command buttons in Model Driven App using Power FX formula

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.

Hide / Show command bar buttons in Model Driven App using Power FX formula

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.

How to hide / show command buttons using Power FX formula?
  • 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 gridButtons placed here are displayed in the home page grid of an entity / table
Main formButtons placed here are displayed in the forms of an entity / table
Subgrid viewButtons placed here are displayed in the subgrid views of an entity / table
Associated viewButtons placed here are displayed in the related entity’s associated view
  • We will select the command bar customization on “Main form” as shown below.
buttons Power FX formula
  • 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.
buttons Power FX formula
  • Provide a name to your button, navigate to the property “Visibility” and select visibility as “Show on conditional from formula” as shown below.
buttons Power FX formula
  • 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)
 command buttons in Model Driven
  • 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.

 command buttons in Model Driven

Thus, we learned to hide / show command buttons in Model Driven App using Power FX formula.

5 2 votes
Article Rating
Subscribe
Notify of
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
R. Flem
3 months ago

Great stuff… too bad it doesnt work with custom Choices.

error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.