Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
Menu

Run ‘For selected item’ flow from non-default environment (Power Automate)

Posted on January 18, 2023January 22, 2023 by Tom

“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
    }
  }
}
Power Automate run item non-default environment

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.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes