Modern commanding in model-driven app and Power Automate
This step-by-step guide illustrates how to integrate a Power Automate flow with a model-driven app in Power Platform, utilizing modern commanding. By following these instructions, you’ll establish a streamlined process where a specific action, such as clicking a button, initiates a flow within your application.
Step by step
1. Create a Date Column Trigger
Begin by creating a date column within your app’s data model. This column will serve as the trigger for the Power Automate flow when it’s set.
- Add the new column to the form so it will be available to Power FX. Make sure it is locked. It should be set by the system not the user.
- Make sure the phone number field (or any field you want to make changes to) is also added to the form. This field will be formatted by the Power Automate flow when the button is clicked.
2. Configure the Power Automate Flow
You will create a flow that will format the phone number when the Format Phone Number button is clicked. The first action will be a When a row is added, modified or deleted trigger.
3. Specify Modified as the change type to trigger the flow.
4. Choose the relevant table and column to monitor for changes. The logical name should be specified here.
3. Create a new command/button in the command designer
Open the model-driven app. In the model-driven app select Edit commandbar. You will now create a New Command.
5. In the top bar select New → Command. A new button with the text NewCommand is added to the command bar. Configure the command properties to the right.
- Label: Set the user-facing name for the command.
- Icon: Choose an icon to appear on the button.
- Tooltip: Provide a brief description of what the command does.
- Action Type: Choose “Power Fx” as the action type for this command.
6. Define the button’s functionality to execute a Power FX Patch function upon click. This function will update the locked date field with the current timestamp using Now(). Subsequently, any modification to this field will activate the Power Automate flow since we added the trigger to the Power Automate flow to trigger on Modify for this column.
Here is the Power FX code that will run onSelect for the Command.
Patch('[The table with the trigger column]',Self.Selected.Item{'Power FX Flow Trigger': Now()}); Notify('The number formatting has been triggered. Please refresh the page to see the results.')
4. Test the functionality
Make sure the app and the changes in the command designer are published. Run the app. Add a unformatted phone number to the form.
7. Click the FX Format Numbers button.
8. The Power Fx will update the trigger date column with todays date and the notification message will be displayed at the top of the page. When the page is refreshed the phone number should be formatted.