As I have blogged about previously, email and note attachments in Dynamics 365 can eat up a lot of valuable space in a Dynamics 365 database.
Attachment Management on Appsource
There are a number of 3rd party solutions on the market to address this, on AppSource is the Microsoft Labs “Attachment Management” solution.

The solution is provided as a free App. The caveat is that the App has no quick support mechanism (but it is supported) and has had a few issues during its evolution. From the reviews it appears that for some it works, and for others it doesn’t. I found that the instructions can be a bit unclear, but with some effort I was able to get it working. I would advise against using this type of solution on large enterprise projects where a supported 3rd party solution may be a better choice. E.g. North52
In order to get support, you can send an email to appsnotify@microsoft.com (and not via regular Dynamics 365 support channels). I have found that the Microsoft Labs team does make an effort to assist with any issues and usually will respond within at least a day.
Attachments not Moving Issue

An issue that I experienced recently was the “Move to Blob” process did not seem to move email attachments. This could be due to the process timing out (exceeding the 2 minute plug-in threshold) or a particular attachment hanging up the process. One of the solutions suggested by Microsoft Labs support was to use a Logic App instead of the plug-in.

Logic Apps to the Rescue!
This particular Logic App can also come in handy when needing to migrate a bunch of attachments (possibly after a data migration). You can monitor the progress in Azure and also easily identify potential issues.
This also is a great example of using Azure Logic Apps to address business issues in Dynamics 365.
Note that I personally DID NOT write this Logic App. This was created by I believe Suresh Guduru and the Microsoft Labs team. Just want to give credit where credit is due!
While the Logic App is an elegant solution, I found the instructions a bit confusing so here are the step by step method that I used to get it working.
You will need the following;
- Dynamics 365 Instance
- Azure Subscription
- Ideally the Attachment Management tool installed from AppSource
Getting and Installing Logic App from GitHub on to Azure
The Logic App can be access via this link on GitHub.
Scrolling down, you will see buttons that will assist in loading the Logic App on your Azure subscription. There are 3 available Logic Apps, 1 for note attachments, and 2 for email attachments, one with filters based on the “CreatedOn” date.

Clicking on the Deploy to Azure will then attempt to install the Logic App on your Azure instance. If you manage multiple Azure subscriptions then I suggest you login first to the Azure portal you want to install the logic app on.
You will need to fill in some information;
- Azure Subscription – self explanatory
- Resource Group – I used the same group as my attachment containers, but you can create a new resource group
- Location – ideally the same location as your Dynamics 365 instance
- Login App Name – any name you want to give it
- Logic App Location – again, ideally the same location as your Dynamics 365 instance
- Dynamics Connection Name/Display Name – these can be anything you want but ideally descriptive of your Dynamics 365 instance.
- Azure Connection Name/Display Name – again, anything you want but ideally descriptive.
- Azure Blob Account Name – this needs to match the name of your Azure Storage Account
- Azure Blob Access Key – Locate the Access key as per screenshot below. Do NOT use the “Secure Access Signature”

Once you have filled in the values and accepted the terms, click Purchase. Note that there is no direct cost for the Logic App but it will cost Azure credits (but very little).
After a few moments the Logic App will be installed. Note that it will attempt to run but will fail as we have not yet setup the various parameters and authorizations.

Authorizing Dynamics 365
You will need to authorize the Logic App to access Dynamics 365.
Click on the API Connections and click to open the D365 API connection (here is where you can edit other settings if you mis-installed the Logic App)

Click on the warning message “This connection is not authenticated”
You will need to click on the Authorize button.
Enter in your Dynamics 365 credentials, ideally use an Application Account.
You should get a message that Dynamics 365 authorization was successful. Save the API connection.

Edit the Logic App Code
The next step is to update some of the variables in the Logic App code itself. Click on “Logic App Code View” to view the code.
You will need to get the following
- Dynamics 365 Unique Orgname
Note that this is NOT the name you find in the URL but the actual “orgXXXX’ name. This cna be found in the Dynamics 365 Settings -> Customizations section.
In the Logic App Code, replace the CRMORGUNIQUENAME_TOBE_REPLACED with the org Unique name AND the crm region (e.g. North America -> crm, Canada -> crm3, etc) Note that there are 2 places where this needs to be changed.

If your Azure notes container is NOT named the following:
- notesattachments
- emailattachments
Then you also need to update the container name in the Logic App Code:

The other thing to note is that there is a $top parameter that will indicate how many times for the Logic App to loop. This is key for testing or running the Logic App in small batches. However, it does run quick, and I found it processed about 100 attachments in about 18 seconds.

Be default, the Logic App will run once every 300 days. This is fine for testing but you may want to run it weekly or daily depending on your requirements.
"Recurrence": { "recurrence": { "frequency": "Day", "interval": 300 }, "type": "Recurrence"
Finally, choose “RUN” to test the Logic App. If the settings were correct, you should see it process. If you get any errors, you can drill down for more information and update accordingly. I found on my first few attempts it was the wrong App key used, the orgname and other minor misspellings.

To see if the Logic App actually worked, you can view the Azure storage reports to see the attachment numbers in Dyn365 and Azure.


Summary
The Attachment Management App from Microsoft Labs has evolved since being released last year. Despite some criticisms, the app is supported and the team has listened and made updates (e.g. resolved conflicts with the D365 portal).
The Logic App is a nice addition to the overall solution and also highlights the power Azure can provide to Dynamics 365. Great work by the Microsoft Labs team!
Nick Doelman is a Microsoft MVP for Business Applications. Join Nick and other MVPs at Dynamics 365 Saturday in Mississauga on May 5th!
Your article saves my life. Thank you so much!
LikeLike
Hi Daniel, Thanks for the kind words! I appreciate it.
LikeLike
Great Article! Do you know if the Logic App limits itself to attachments on the entities you’ve configured inside the Attachment Management solution, or if it just uploads everything?
LikeLike
I believe it does limit itself to just the entities you specified.
LikeLike
Hi Nick,
I suggest to provide an original LogicApp source: https://github.com/anilvem1/LAMoveCRMAttachmentsToBlob/network/members
Some branches have better explanations.
This article would be useful to understand this Logic app:
https://www.dynamicsforcrm.com/migrating-attachments-in-bulk-from-dynamics-365-to-azure-blob-storage/
LikeLike
Thanks for the links. With file capacity storage now being built into CDS, this technique for storing attachments for Power Apps (incl. Dynamics 365) is no longer necessary going forward, however there still might be folks who haven’t moved over to new capacity model yet, so these techniques might still have some life. https://docs.microsoft.com/en-us/power-platform/admin/capacity-storage
LikeLike
What would be really cool is if you have a version of your solution that could *reverse* the process… take an attachment out of blob storage and put it back as an attachment. I know this sounds really weird, but with the new file capacity model, there are likely folks who implemented a solution like this, but now might want to reverse it to take advantage of the file capacity instead. Just an idea! Cheers, Nick
LikeLike
Is there any way to modify the logic app to order by oldest to newest?
LikeLike
Sorry for the delay. I am not an expert on Logic Apps but I think you could modify the query using the $orderby tag to sort the order. I hope this helps. Cheers, Nick
LikeLike