Model Driven App | Command Bar | Power Fx formula examples
I’ve written an introductory article on Command Bar when the feature was in preview state. Now that the Command Bar evolved with Power Fx, lets learn few scenarios using Command Bar with Power Fx.
I am taking a scenario of Cloning a record with following design:
- Add new Command button on Command Bar
- On ‘OnSelect’, write Power Fx Patch formula to create a new record from existing record.
- Write a Visibility rule, to display the Command button only on ‘Edit’ form.
Lets get started.
Add a new Command button and implement Clone functionality:
- Open the Model Driven App in editor and select a table which you would want to place the Clone button. click on ‘Edit command bar’.
- Selected ‘Main form’ as we are going to add ‘Clone’ button on form.
- Add a new ‘Command’ button and provide details like Label, Icon, etc…
- We need to write ‘Power Fx’ formula on ‘OnSelect’ event of the command button.
- We can write the formula in the formula text box at the top but its not intuitive. One option is to write the formula by clicking on ‘Open component library’, which opens up Canvas app editor.
- Click on ‘Open component library’.
- Point to be noted is every time you add a new Command button, it creates a component in the background.
- Once the ‘Command Library’ window opens up, under ‘Tree View’, you can see a separate component for each command button you have in your MDA.
- Coming back to our Clone scenario, select the ‘Clone Customer_1’ component and on ‘OnSelect’ event, write the PowerFx formula to clone the current record.
- I am using Patch function with Defaults(Customers) which creates a new record.
Notify("Cloning the Customer...");
Patch(
Customers,
Defaults(Customers),
{
Name: "Clone - " & Self.Selected.Item.Name,
Gender: [@Gender].Male,
'Date of Birth': Self.Selected.Item.'Date of Birth',
'Mobile Number': Self.Selected.Item.'Mobile Number'
}
);
Notify("Cloning completed successfully !!!");
- Click on ‘Publish’ icon and close the window.
- Come back to the MDA editor and you would see the clone Power Fx formula prepared in Components library screen.
- Click on ‘Play’ to test the ‘Clone Customer’ button in your MDA.
- Open a Customer record and click on ‘Clone Customer’ button.
- Up on successful clone, you would get the ‘Cloning completed successfully’ notification and you can even open the new cloned record.
Command Visibility Formula:
- Now that we achieved the clone functionality, lets add a validation by showing the ‘Clone Customer’ command only on Edit form.
- Go back to MDA editor and select the ‘Clone Customer’ command and set Visibility as ‘Show on condition from formula’.
- In the formula, specify formula as
Self.Selected.State = FormMode.Edit
- Publish and Play the App and you would see the ‘Clone Customer’ button only on edit form but not on create form.
🙂
Advertisement
Categories: Model Driven Apps, PowerApps
Tags: Command Bar, Power FX, Visibility
Comments (0)
Trackbacks (0)
Leave a comment
Trackback
Stats
- 1,580,268 hits
Tweets
- RT @MikeFactorial: Big things are coming to the #CoEStarterKit. So, @ManuelaPichler_ and team are building the tension for the April releas… 2 weeks ago
- New blog post : Boost conversations using GPT in Power Virtual Agent (PVA) rajeevpentyala.com/2023/03/08/pow… 2 weeks ago
- RT @PPDevWeekly: 🔥 Going Live: Power Platform Dev Weekly 155 bit.ly/PPDevWeekly155 This week's cover story by @RajeevPentyala With gre… 2 weeks ago
- RT @caseyburke21: Pipelines is now generally available! Huge congratulations to the team and all who have supported reaching this milestone… 3 weeks ago
- New blog post : Call Dataverse actions directly in power-fx rajeevpentyala.com/2023/03/01/ste… 3 weeks ago
Join 405 other subscribers
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Step by Step] Power Apps | Show pop ups in Canvas App
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- Power Platform - Pass json collection from Canvas App to Power Automate
- [Log4net] Exception while reading ConfigurationSettings
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- Power Automate Flows | 'Callback Registration Expander' System Jobs stuck at 'Waiting For Resources'
- [Step by Step] Postman tool with Microsoft Dataverse Web API
- Retrieve associated records (N:N related)