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.
Hi, it would be helpful if you provided a more detailed error message but I can see you're trying to delete the wrong type of attachment record. As I mentioned in my previous comment there are 2 tables named attachment in the drop down. You must make sure to delete the activity mime attachment record.
Could you perhaps provide some more information about the error?
I'm also looking into a solution for this.
Hi @carterbarry88 ,
Can you please explain in the details? or some more pic pls?
I would like to delete the attachment , the problem is i'm getting error while "Delete the record or update the record".
I got the rows,
After the execution ,
I really appreciate if you can help.
Thank you!
Hi there,
Thought I would add my two cents here. Potentially there has been an improvement in the connector since this was posted, but I was able to delete a record from the "Activity Mime Attachment" table using the Dataverse Connector.
It is possible to select the "Attachments" entity in the drop down list. Note there are 2 entities named "Attachments". In my environment, it was the first one. To make sure of your selection, "peek code" and ensure that the action is pointed at the "activitymimeattachments" entity. I was able to point the following Dataverse actions against the table:
- Get row
- Delete row
- List rows
After running the action, the attachment was removed from the email record
Hope this helps someone
Thank you so much for your help here, its very much appreciated.
Best regards
Hi @mcgeeardee
The 'Get Base URL' is a Dataverse List rows action. Just point it to a table that will have records in it, e.g. the accounts table.
Get just 1 record to reduce the data. the output of this step is then used to create the URL path in the expression
uriHost( outputs('Get_Dataverse_BaseURL')?['body/@odata.context'] )
Hello such a useful tool and I have looked for something like this for a very long time.
I need help with the Get Base URL Step. Would you please detail how you created this?
Thank you again
Great, was thinking that but the icon in the image above confused me (its a dataverse icon isnt it?)
So the variable value is something like: e.g. http://<environmentname>.crm11.dynamics.com
Urfan
I just initiated an variable where I hard-coded the environment URL (making it flexible in the steps afterwards)
WarrenBelz
791
Most Valuable Professional
MS.Ragavendar
410
Super User 2025 Season 2
mmbr1606
275
Super User 2025 Season 2