List, Filter and Delete Flows in Power Automate

The irony of creating a flow to delete some flows is pretty significant but hear me out, I have a good reason why. You can use this flow to list and filter flows, to do whatever you wish, in this case I want to delete the flow but obviously the usual health warnings apply when you are deleting things. With great power comes great responsibility yada yada. And do not ever question the power of cascading delete on Account records in Dataverse.

Why do you have so many flows to delete?

When you create a Customer Insights - Journeys ‘Journey’ it creates multiple power automate flows in the background with the prefix CXP_ that handles all the automation you built in your journey. Each journey can have 5+ flows running behind the scenes and if you edit the journey a new set of flows are spawned so it’s a number that can grow really quickly without trying too hard. Once the journey is complete or stopped, the flows are automatically turned off and left to fester in the default solution forevermore. I mean it’s not technically doing any harm there but it’s a bit sloppy, they get in the way when your trying to find a flow and for anyone who doesn’t know CI-J it’s concerning.

Once the flow is turned off, it’s of not benefit to be there. Deleting these flows does not result in any loss of analytics or anything like that. Once their job of automation is complete, they are obsolete.

The Flow Deleting Flow

This example shows you how to filter for flows which start with CXP_ and are turned off but you can adjust the filter query as needed. You can point this flow at any environment you wish so long as you have the sufficient permissions to this environment and your DLP policies allow.

Start the Flow

You can start this flow however you like, I just used an on demand button but this could be scheduled to run daily/weekly for example.

Find the Flows

Ok before anyone gets in a flap. I am aware there is a ‘List Flows as Admin (V2)’ action which can be expanded to reach beyond 250 records if you turn on pagination (example here) but you then have to haul back all the flows and column, then filter and then delete. instead we can use a single HTTP request which already filters to give you the disabled CXP_ flows and only returns a few columns of data (name, id and state).

Name: ListCXP FlowsTurnedOff
Method: GET
Url of the request:

https://environmenturl.crm6.dynamics.com/api/data/v9.2/workflows?$filter=category eq 5 and statecode eq 0 and startswith(name,'CXP_')&$select=statecode,workflowid,name

To create a connection for the HTTP with Extra ID (preauthorized) connector, you just need to your your dynamics URL for both inputs.

Delete the Flows

Now you just need to loop through each of the flows and delete it, for which the Power Automate Management connector does a lovely job.

Control - Apply to each
Name: Each Flow
Select an output from previous steps: body('ListCXPFlowsTurnedOff')?['value']

Power Automate Management - Delete Flow
Name
: Delete Flow
Environment: Your environment
Flow: items('Each_Flow')?['workflowid']

To make your loop run a little faster you can turn on concurrency control but don’t go too high otherwise your flow may be throttled for too many requests within a short timeframe.

Flow Fratricide

And lets end on a joyful note that you just built a flow that commits Fratricide ‘the act of killing a brother’. But it’s a sacrifice that has to be made.

Previous
Previous

Lead and Contact form Insights tab in Customer Insights - Journeys (without editing Form XML)

Next
Next

Manage Email Bounces on Lead or Contact Views & Forms in Dynamics 365 Customer Insights - Journeys