Forum Discussion
Trigger flow from web part
Hi mingyk,
To trigger a flow from a SharePoint web part you can try to use a Power Apps button.
Here are the steps on how to create a Power Apps button and trigger a flow from a SharePoint web part:
Create a Power Apps button.
Go to Power Apps and create a new canvas app.
Add a button to the app.
In the OnSelect property of the button, add the following code:
Launch( "https://flow.microsoft.com/manage/environments/{EnvironmentName}/flows/{FlowID}/run" );
Replace {EnvironmentName} with the name of the environment where your flow is located and {FlowID} with the ID of your flow.
Save and publish the app.
Embed the Power Apps button in a SharePoint web part.
- Go to the SharePoint page where you want to add the button.
- Add a Power Apps web part to the page.
- In the App property of the web part, select the Power Apps app that you created.
Create a flow to be triggered by the Power Apps button.
- Go to Power Automate and create a new flow.
- Select the "When a button is clicked" trigger.
- In the OnSelect property of the trigger, select the Power Apps button that you created.
- Add the actions that you want to perform in your flow.
- Save and run the flow.
Here are some useful links regarding your issue:
- Create a Power Apps button: https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/controls/control-button
- Embed a Power Apps button in a SharePoint web part: https://www.c-sharpcorner.com/article/embed-powerapp-form-on-sharepoint-page-microsoft-powerapps-webpart/
- Create a flow to be triggered by a Power Apps button: https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/how-to/trigger-flow
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
- maroodzantSep 03, 2024Copper Contributor
Hi,
I face the same problem that was stated in the original post.
Sadly the solution presented creates a button for a single powerapp call
However, as the included webpart is a list (or in my case) a library, the powerapp call should act on a single line in the library or list.
Is there a way to achieve that?
For example, can I include information about a selected item in the list/library to the flow call for the button you suggest. Even then I have an issue.
In the library I have set up the column with the flow-starting button with the column formatting option. In that script I also included conditions that would show or not show the button for that line, In that way I can prevent the flow being triggered if not all required fields are filled for the item. With a single button outside of the list that would also prove difficult, i fear.
I added the library as a web part so I could add a general description about the library and the available views. So right now, I either have to forego the description or the automation.- rubalcadajrOct 31, 2024Copper Contributor
You can achieve this by first triggering your workflow with the For a selected file SharePoint trigger. You can require input from the user when starting the workflow from this trigger (I required description of the change to the document.) Next, add a single line text column in your SharePoint library, and in the column formatting section, add this:
{"$schema":"https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json","elmType":"button","customRowAction":{"action":"executeFlow","actionParams":"{\"id\": \"{ID_OF_YOUR_FLOW}"}"},"attributes":{"class":"ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"},"style":{"border":"none","background-color":"transparent","cursor":"pointer","visibility":"=if(((indexOf([$ContentTypeId],'0x0120')) == 0),'hidden', 'visible')"},"children":[{"elmType":"span","attributes":{"iconName":"Flow"},"style":{"padding-right":"6px"}},{"elmType":"span","txtContent":"{WHATEVER_YOU_WANT_YOUR_BUTTON_TO_SAY}"}]}
My workflow started an approval process for a document in the library. The formatting above looked like this in the list.
and this is the beginning of my workflow
Hope that helps!