0

At the moment it is possible to run the same Power Automate workflow on the same SharePoint Library item. (i.e. a 2nd instance of a workclow can be created before the 1st instance has finished). This causes all sorts of problems, nevermind poor user experience. The option of a further workflow needs to be available to run on other items.

In SPD days, the same workflow was prohibited to start on the same item and the start button was disabled.

Concurrency does not solve this one. Any suggestions?

Thanks

1 Answer 1

0

There's no direct way to prevent a Flow instance from getting started on an item when an instance is already in progress on the same item. However, I think, we can take a few steps to minimize the chances of having multiple instances of the same flow running on the same item to minimize data corruption.

My test is based on a custom list (Issues) and Power Automate trigger on [For a selected item]. But this can be applicable to Libraries as well with [For a selected file]

Here are the steps that I've tested with:

  1. Add a Yes/No type column, IsWorkFlowRunning, to the list with default value being set to No (false).
  2. Create a flow with [For a selected item] trigger
  3. Add [Get item] and retrieve properties of the item by [ID]
  4. Add a [Condition] to check if [IsWorkflowRunning]=false
  5. If "false", update the item by setting [IsWorkflowRunning]=Yes (true)
  6. Add all the actions needed in the flow to meet business requirements
  7. once everything is done, update the item again by setting [IsWorkflowRunning]=No (false)
  8. Format [IsWorkflowRunning] column by using the following JSON (replace the flow ID).
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if([$IsWorkFlowRunning]==false, 'block', 'none')"
  },
  "children": [
    {
      "elmType": "button",
      "txtContent": "Run Workflow",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\":\"2cc9148a-744d-413c-9e3d-6849a6f00b46\"}"
      }
    }
  ]
}

Expected results:

  1. Button to run the flow on the selecdted item will not be avaialble when [IsWorkflowRunning]="Yes"
  2. Even if the user is able to click the button due to latency, condition in the flow will prevent data from getting corrupted.

Screenshot of List showing JSON formatted button

enter image description here

Screenshot of the Flow

enter image description here

2
  • Thanks for the detailed explanation. Few of things I forgot to mention. The 1st flow starts a 2nd flow (child). I cannot update columns because I cannot check-out due to Approvals. The workflow can terminate in multiple places (and at times due to Timeout). Hence, even if I could update item, the update action will need to handle the multiple exit scenarios. :( . Does FLow have an api available so I can check every flow thats running against an item ID ? .. I read something to do with connectors not being available for FLOW... Commented Feb 12, 2021 at 8:45
  • I don't think you have to check out to update document's metadata property. No, I don't think currently there is any API or Flow action that we can use to find out how many instances of are running Commented Feb 12, 2021 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.