USING MODERN COMMANDS WITH FX FORMULA

Empower your employees to achieve better results. 

The use of the new Modern Commands compared to the classic ones offers a great advantage, it allows the use of Power Fx formulas both to perform actions and to define visibility rules. This eliminates the need to develop scripts in JavaScript, making the configuration of these commands a low-code task. 

In this article, we will explain an example of use and its application. Let’s imagine we have an application to manage our quotes and we want to add a button that indicates a quote has been lost.

Demo video

Here is a video with the step-by-step guide on how to implement the FX formula in the command bar:

Step by step

Adding the new button

  • Select the Application: 

a. Open the application in the Power Apps designer.

b. Select the table where you want to add the button, in this case, the “Quotes” table. 

c. Click on the three dots next to the table views and select “Edit Command Bar.” 

 

  •  Choose the Button Level: 

a. A window will appear asking at which level you want to create the button. Select “Main Form” to add it at the form level. 

b. Here is a description of the available options: 

    1. Main Grid: For commands in the main grid view, ideal for actions affecting multiple records.
    2. Main Form: For specific commands in the main forms, useful for actions on a single record.
    3. Subgrid View: For commands in subgrids within a form, perfect for actions on secondary records.
    4. Associated View: For commands in associated views showing related records, ideal for managing relationships between records. 

 

  • Add the Button: 

a. In the top left corner, select “Add Command” to add a new button. 

Button configuration

  • Name and Icon:

a. Assign a name and an icon to the button. 

b. Configure the tooltip that will be displayed when the user hovers over the button. 

 

  • Define the Action:

a. In the “Action” property, select “Run Formula” to use Power Fx formulas. 

b. In the formula bar, enter the action you want to perform. For example:

				
					If( 

    Confirm( "Are you sure you want to mark the quote as lost?",  

            { Title: "Confirm Mark Lost", ConfirmButton: "Confirm", CancelButton: "Cancel" }  

    ), 

    Patch(Quotes,Self.Selected.Item,{'Status Reason': 'Status Reason (Quotes)'.Lost ,Status: 'Status (Quotes)'.Inactive}); 

    Navigate( Self.Selected.Item ) 

) 
				
			
  • If: Evaluates a condition and executes actions depending on whether the condition is true or false.  
  • Confirm: Displays a confirmation dialog box. If the user confirms, it returns true; if the user cancels, it returns false.  
  • Patch: If the user confirms, updates the selected record in the Quotes entity, changing its status to “Lost” and “Inactive.”  
  • Navigate: Redirects the user to the selected item, providing a smooth experience and refreshing the form.

Configure visibility rules

  • Define the Rule: 

a. In the properties panel, select “Visibility” and choose “Show on condition from formula.” 

b. Enter the formula for the visibility logic: 

				
					Self.Selected.Item.'Status Reason' = 'Status Reason (Quotes)'.'In Progress'
				
			
  • Self.Selected.Item: Refers to the currently selected item.  
  • ‘Status Reason’: Field of the selected item that contains the status reason.  
  • ‘Status Reason (Quotes)’.‘In Progress’: Compares the value of the ‘Status Reason’ field with ‘In Progress.’ 
  • Condition Evaluation: 
    1. If the value of the ‘Status Reason’ field is ‘In Progress,’ the condition evaluates to true and the button will be visible. 
    2. If not, the condition evaluates to false and the button will not be visible. 

Conclusion

We have seen how to use Power Fx formulas to configure buttons in Power Apps without the need to develop scripts in JavaScript. This makes it easier to create actions and visibility rules efficiently and with less code. 

Here is a visual representation of how the process will be implemented within the Model Driven App.

Find out how we can take your business to the next level!

This website uses own and third party cookies for its proper functioning and for analytical purposes. It contains links to third-party websites with third-party privacy policies that you can accept or not when you access them. By clicking the Accept button, you agree to the use of these technologies and the processing of your data for these purposes.    More information
Privacidad