556 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
|Writing a flow to delete all of your flows
|After every training course I have to manually delete every flow from every delegate's computer. This takes ages, and stresses me out. There must be a better way ... mustn't there? Maybe I should write a flow to delete all my flows?
I surely can't be the only person who is frustrated by having to delete my flows one by one!
You can select each flow individually and delete it, but I want to bulk delete.
Having told people that this wasn't possible, I now realise that you can use the Power Automate Management connector to get access to your flows, loop over them and delete them one by one!
The example below includes a check that you're not trying to delete the running flow - otherwise you would end up with an ouroboros.
A bit of preparation: when you loop over your flows, you're going to have to exclude the current one. You can use the workflow() function to get information about the current running flow:
What the workflow function shows for a flow called test. This means that you can use workflow()['tags/flowDisplayName'] to get the current flow's display name.
Start by creating a flow to list out all of your flows:
The flow you should create.
The List My Flows action can be quite hard to find, but it is there:
Eventually you should be able to see your Power Automate Management actions .
You'll need to choose an environment in which you want to list flows:
Choose in which environment you're working.
You now need to use the Get Flow action within a loop to look at each flow in turn:
First add this action.
Choose to use dynamic content for your flow name:
Which flow do we want to get? The one with each name as you loop over the flows.
Choose the Flow Name (this is the internal name, not the one displayed in your flow window):
This should really be called the flow id to be consistent with other parts of Power Automate.
This will automatically add in an Apply to Each loop:
You're now looping over your flows.
It's time now to add a condition to your flow:
The condition is that the Flow Display Name should not be the current flow's display name (see earlier in this blog for why we use this workflow() expression.
You're creating a dangerous flow! It might be worthwhile adding a couple of Compose actions to test your flow at this point:
You should find that all but one of the iterations round your loop goes down the True path of the condition.
You can now set what happens for all flows apart from your current one:
Add an action if your condition is true (that is, if this flow's display name isn't the same as the current flow's display name).
Add a Delete Flow action:
You'll need to scroll down quite some way to find this action.
Choose to delete the flow whose name is the one you're currently looking at:
Make sure you choose the flow id (ie the Flow Name dynamic content).
You should now be able to run your flow!
The flow should look something like this!
When you return to your flows list, you should see just the flow you've been working on:
The last flow standing!
Be sure to refresh your screen, otherwise you won't see the latest up-to-date list (which can be confusing, as the next time you run your flow it will only loop over a single flow; all of the others have been deleted).
If you want to repeat this for other accounts, you'll now need to export the flow you've written from this account and import it into others in order to be able to run it, as shown in this separate blog.
Some other pages relevant to the above blog include:
25 Aytoun Street