Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your 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.

4 thoughts on “Run ‘For selected item’ flow from non-default environment (Power Automate)”

  1. Dan says:
    February 8, 2023 at 1:36 pm

    nice!

    Reply
  2. Haroldbk says:
    March 14, 2023 at 2:52 pm

    This does work nicely.
    My only concern is that once the button is clicked it goes away so it can’t be clicked again.

    Reply
    1. Tom says:
      March 21, 2023 at 5:58 pm

      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).

      Reply
  3. Daniel says:
    May 22, 2023 at 7:04 am

    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

    Reply

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!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

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.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes