blog.atwork.at

news and know-how about microsoft, technology, cloud and more.

Trigger a Power Automate Flow through a SharePoint List Item

Background

Power Automate is a great tool to automate SharePoint based Tasks, e.g. Document Approvals, Notifications,... The flows can be triggered by a new or changed Element / Document in SharePoint, but very often, we want the user to start a flow for a specific, selected document. For that, Microsoft is Providing a Power Automate Trigger called "SharePoint - Start for the selected document", which can be triggered for the selected document in SharePoint. The flow gets the ID of the selected document and can do anything you want with that document. In this post, I explain, how to trigger a flow, that is located in another environment than the default environment

How does the integration work

This is great - BUT - in the past the flow needs to sit in the default Power Platform Environment, that SharePoint can trigger it. The reason for that is easy explained - let's have a look on the integration in the SP List.

To start the flow from the SP List, we add a text field to the list, add a custom formatter to that field and reference there to the ID of the Flow

Demo 
Title v 
-Item 1 
Flow v 
Start my FLOW 
Add column

The JSON for the custom formatter looks like that:

{

  "$schema": "https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "style": {
    "border": "none",
    "background-color": "#0029b0",
    "color": "#0078d7",
    "cursor": "pointer",
    "width": "100px",
    "margin": "5px",
    "border-radius": "20px",
    "visibility": "visible"
  },
  "children": [{
    "elmType": "button",
    "txtContent": "Start my FLow",
    "style": {
      "border": "none",
      "background-color": "transparent",
      "color": "white",
      "cursor": "pointer"
    },
    "customRowAction": {
      "action": "executeFlow",
      "actionParams": "{\"id\": \"0000000-0000-0000-0000-0000000000\"}"
    }

  }]

}


The relevant part is

"customRowAction": {
  "action": "executeFlow",
  "actionParams": "{\"id\": \"0000000-0000-0000-0000-0000000000\"}"

}

The Problem

You see that the action "executeflow" only takes a Parameter "id" which is the flow id. If the flow is not located in the default environment, the button will not work. From a good Power Platform Governance not a very nice approach, as Microsoft is telling us to place "real world/mission critical" Flows in other Environments than the Default Env.

But since a few weeks, there is new way to reference to the flow which has the Environment ID included.

To find that link, let's switch to the Power Automate Maker Workbench at https://flow.microsoft.com

First lets validate we are not in the Power Platform default environment

Environments 
Megan Bowen's Environ... 
directed 
Environments 
p Search 
x 
V 
Contoso (default) 
Megan Bowen's Environment

Next I create a very simple flow with the SP-trigger "for the selected item"

For a selected item 
Site Address 
List Name 
+ Add an input 
Demo - https://m365x88854538.sharepoint.com/sites/Demo 
Demo 
4. 
Send an email notification (V3) 
+ New step 
Save

After saving and exiting from the flow workbench, we can get the identifier of the flow, via the "Export" Menu

Edit Share Save As 
Delete 
Send a copy 
Submit as template 
Export v 
Package (.zip) 
Get flow identifier 
Analytics 
Turn off 
C) Repair 
Flows 
SP Demo 
Details 
Flow 
SP Demo 
Owner 
Megan Bowen 
Status 
On 
Created 
Aug 5, 01:59 PM 
Modified 
Aug 5, 01:59 PM

Environments 
Megan Bowen's Environ... 
Get flow identifier 
x 
Use this detailed identifier to reference this now in 
manual flow irm•cation scenarios like running a now from 
a SharePoint column button 
vi/25e9b340-aeb6-e28a-988b-Oa5a6eb..

The identifier looks like that

v1/00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000

And here is the magic - the ID consist of the the Environment ID + the Flow ID. We can us that in the custom formatter in the SharePoint List

" customRowAction" : 
"action": "executeF10w" , 
"actionParams" : 
\ "VI/ 
eeoeeeae-aeea-eeae-aeea-eoeeeaøeaeee/ 
eeoeeeae-aeea-eeae-aeea-eoeeeaøeaeee

And we can the start the flow from the SP List

+ New 
Demo 
Title v 
- Item 1 
Run flow 
sp Demo 
Owner: Megan Bowen 
Add column • 
Flow 
Start my FLOW

Why is this so important?

In a good Power Platform Governance, we (and also Microsoft) is recommending to use the "Default Environment" as a "Personal or Playground" Environment, not as a Productive Place. But as long as we could not reference to other then the Default Environment from a SharePoint List to start a Flow, we had to use the Default Environment for that. With that trick, now it is possible to have a "clean" Default environment (maybe using the Power Platform CoE Starter Kit).

If you want to learn more about a good Power Platform Governance, contact us!

Loading