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:
- Add a Yes/No type column, IsWorkFlowRunning, to the list with default value being set to No (false).
- Create a flow with [For a selected item] trigger
- Add [Get item] and retrieve properties of the item by [ID]
- Add a [Condition] to check if [IsWorkflowRunning]=false
- If "false", update the item by setting [IsWorkflowRunning]=Yes (true)
- Add all the actions needed in the flow to meet business requirements
- once everything is done, update the item again by setting [IsWorkflowRunning]=No
(false)
- 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:
- Button to run the flow on the selecdted item will not be avaialble when [IsWorkflowRunning]="Yes"
- 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
Screenshot of the Flow