After scouring the web for a solution to remove email attachments in bulk without affecting the original messages, I finally discovered a way to achieve this with the help of power automate. In this post, I will share my method with you.
The attachment tables in Dataverse (there are more than one) are not easy to delete from. The standard Dataverse connector cannot handle this task.
The overall flow looks like this
The dataverse action is just a little trick to get the URL to the environment where the flow is running. This way the rest of the flow will use dynamic references and no hardcoded URLs
Then I determine a cutoff date. From all emails older than this date the attachment should be removed.
Then two HTTP actions follow. There was a name change recently and currently called 'HTTP with Microsoft Entra ID (preauthorized)'
I like to use this connector for fancy stuf that you can do with the Dataverse webAPI, but not with the dataverse connector.
The first HTTP call gathers the attachment. Of course, you can create your own filters here.
The second HTTP loops through all the found attachments and executes a delete action.
https://@{uriHost( outputs('Get_Dataverse_BaseURL')?['body/@odata.context'] )}/api/data/v9.2/activitymimeattachments(@{items('For_each_attachment')['activitymimeattachmentid']})Remember to set the concurrency in the Apply To Each settings.