“I can’t run my Power Automate flow in the item context menu, could the reason be that it’s on a non-default environment?”
When you use the ‘For selected item’ trigger in your flow, you’re very limited by the location of the flow. It must be in the Default environment of your organisation, otherwise it won’t connect to SharePoint, yet it’s not wise to have all the flows in the default environment. Is there a way to bypass this limitation? To manually start flows on a selected item even from non-default environments?
You’ll have to use a different trigger
There’s no way to add such flow to the list context menu. But if you combine a few pieces of functionality you can achieve the same result.
Add a column and a button to the list
Firstly, add a new column to your list, e.g. Yes/No column called “RunFlow”. This column will tell the flow whether it should start or not.
Since you don’t want users to check this checkbox manually, you should allow them to do it with a button.
Not only can you trigger a flow, you can also update a column using the JSON column formatting. The piece of code to do that is as below.
"customRowAction": {
"action": "setValue",
"actionInput": {
"<columnInternalName>": "<value>"
}
}
In this example, when working with the Yes/No column “RunFlow”, it’ll be:
"customRowAction": {
"action": "setValue",
"actionInput": {
"RunFlow": 1
}
}
Putting the whole JSON code together that’ll also hide the button once the flow is started:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"txtContent": "Run flow",
"style": {
"display": "=if(@currentField != true,'inherit', 'none')"
},
"customRowAction": {
"action": "setValue",
"actionInput": {
"RunFlow": 1
}
}
}
Click on such button will set the value in the RunFlow column to Yes. But that’s only the first part, it won’t trigger the flow yet.
Use a different trigger with a trigger condition
The second step is to use the trigger “When an item is created or modified” instead of “For selected item”. Automatically started flows will work fine from any environment, you just have to block it from running on every update. The flow should start only when the “RunFlow” column was set to Yes – a job for a trigger condition.
@equals(triggerOutputs()?['body/RunFlow'], true)
Once implemented, the flow will start only when users click the button.
Summary
If you want to run a manually started Power Automate on a SharePoint item, but the flow is in a non-default environment, you’ll have to use a workaround. A combination of a new column in the list, JSON formatting on that column to create updating button, and a trigger condition will do the trick. From users perspective it won’t make any difference (if you use buttons to start flows), but the flow can be separated in its own environment.
Just don’t forget to set the column value back to No in the flow if users should be able to start the flow repeatedly.
nice!
This does work nicely.
My only concern is that once the button is clicked it goes away so it can’t be clicked again.
Hello Haroldbk,
that’s why you should “reset” the flag in the flow, once it’s started remove the flag and it’ll show the button again (after a refresh).
Hi
What a neat trick, solves a few issues that I been facing at late. My only question is, I got version history turned on, is there anyway of being able to have this and not fill up the version history?
Cheers
Hello Daniel,
I don’t think it’s doable, not creating version is possible only via HTTP request and not by a generic function.
Hi,
Is there any way to add to this workaround some input values? For instance I want to run the flow that requires several input parameters different for each flow run – how can I do this?
Hello Tomasz,
no, it’s just a button that can automatically update 1 column, it doesn’t support any input from the users.
Thanks Tom, this is great. 1 question though:
I’m having trouble setting setting the column value back to ‘no’ in the flow because my list has other mandatory fields that the ‘Update item’ action requires me to fill in.
I do not wish to change the values of these and many of them are ‘Person’ columns which, if i try to re-set them to their orginal values, results in several nested ‘Apply to Each’ Loops which isnt ideal.
Any ideas?
Another solution would be to create a run-flow button in sharepoint list and in “actionParams” to write the full flow identifier with environment-id (Flow -> Export -> Get Flow Identifier).
smth like “{\”id\”: \”v1//\”}”
This button can run flows also from non-default environments by click