[Update June 2022] The modern command designer is now GA!
Power Fx command bar buttons in model-driven apps is the latest exciting feature to be released into preview by the Power Platform team! Check out my first look video and Casey’s blog post.
This post shows you the steps to follow to add a command bar button on a model-driven form to create a related task for the account record and to only show this when the Credit Hold flag is set to No. This would normally require custom JavaScript and the Ribbon Workbench but now can be accomplished with a simple expression!
First, we must open the new model-driven app editor to access the command bar editor.
Once the app designer has opened we can edit the command bar on the account table. We will create a form button to create a new task for the selected account.
The command bar editor will show all the buttons configured for the account main form. Some of these buttons will not be visible by default but are displayed still in the editor. This is very much like the Ribbon Workbench. The existing buttons are considered V1 buttons and cannot be edited at this time.
Note: You can also upload your own svg
rather than selecting from the out-of-the-box icons available.
This is where Power Fx starts to make an appearance!
Self.Selected.Item.'Credit Hold'='Credit Hold (Accounts)'.Yes
So that we can add a new task, we must add the Tasks data source connection much like we would in a canvas app.
When you open a component library, a lock is taken out to prevent it from being edited in multiple sessions. We must close the editor to release the lock.
Now we can add the Power Fx expression to create the new task related to the account record.
Patch(Tasks,Defaults(Tasks),{Regarding:Self.Selected.Item,Subject:"Credit Check Follow Up"});
Notify("Credit task created",NotificationType.Success);
Once the model-driven app opens, you can open an account record and see the Credit Check button appear only when the Credit Hold column is set to Yes.
Selecting the button will create a new task related to the current record! Notice that the form is automatically refreshed to show the new record created inside the related records.
Note: If you wanted to make the button appear as soon as Credit Hold is set to Yes, you would need to add a call to refreshRibbon
inside the form fields onChange
Event.
To add this functionality using the Ribbon Workbench would have required JavaScript and would be considerably more complex. The new commanding Power FX command buttons unlocks many customizations to low-code app makers!
There are still some requirements that are not yet possible to implement using the new Power Fx Commanding, where you will need to continue to use the Ribbon Workbench. One example of this is the more complex display/enable rules you could create such as visibility depending on the user’s security privileges – but I am hopeful that these gaps will be filled in the ‘fullness of time’ 😊
Watch out for more posts from me on Power Fx commands!
Original Post https://develop1.net/public/post/2021/07/25/commandingv2