Hello Dynamics 365 Fans!
Sometimes you might have a requirement to move data outside of Dynamics, either because of a Business Decision or because of a previous storage model restriction. In either way, we can use Automation tools to connect to Dataverse and move the files (attachments) to another location.
We'll be showing some examples to move attachments to Azure Blob Storage. However, a similar procedure can be used to move data to SharePoint, OneDrive, or to send emails with the attachments. Also, please note this will NOT reduce the file size of your Dataverse environment, since there are other considerations/fields used for this calculation. Also, its important to note that this is a Proof of Concept and that before placing this into production, you should test this and confirm the behavior & File availability.
The first part is to trigger the action. I'm also declaring a couple variables to store the FileName and FileContent. Then, using the Dataverse component to query Dataverse and retrieve the rows of a specific table, on this case, Notes (or Annotation, that stores the notes added within Dataverse)
We can see that at the bottom we have an "apply to each", which will basically allow to move and process each record retrieved from the previous query, in a separated way:
From this previous image, we can see that the first step is to retrieve the details of each record. If you check the output of this step, you'll get a JSON and this is waht we're going to process on the rest of the steps. From here, we'll work with the Filename and DocumentBody:
Take note that the DocumentBody contains the Base64 string associated with the file. That's the reason behind the following steps:
From here, we set the FileName variable as a string containing the GUID of the record, a dash and the original filename. This will then be transformed (using lowercase function), as Azure Blob Storage has a requirement for files to be Lowercase. Following this, we get the string associated with the Document Body and we use a transformation step to convert the Base64 string to binary. Finally, we have a step to store to the files into a specific location: A container of our choice with a specific route, and then we set the BlobName as our filename (that will be lowercase) and the BlobContent to our FileContent, as shown in the following picture:
Once our automation executes, we should start to see our folder being populated:
Again, we must reiterate that this is a proof of concept. Definitive automation should include more steps to validate content, the type of files, for example, as well as extensive test.
Regards