One of the common problems Dynamics CRM Online customers face is storage, especially if you are not willing to pay extra for the storage, or you don’t have enough customers to qualify for free storage. On the other hand, Azure blob storage is quite inexpensive and has loads of features suitable for storing files. You could argue that SharePoint is still the ideal choice if you need proper metadata management, but again, you have Office 365 and licensing aspects to consider.

So, where does this leave you if you simply need your files stored somewhere instead of in Dynamics CRM? Well, you are in luck because with the technologies and functionality available within Azure, you can achieve a simple integration using Azure Logic Apps.

Using Azure Logic Apps

If you are new to Azure, I recommend getting started by signing up for a 30-day trial or even consider the Visual Studio Dev Essential offer which gives you $300 free credit for up to 12 months, which is quite good, especially if you are taking Azure for a test drive and evaluating its components.

If you have an Azure subscription already, then you can easily follow the below instructions.

To get started, head over to the Azure Portal.

 

Then Click on the “+” icon, select “Enterprise Integration” and select “Logic App”.

 

Fill in the required details and click on “Create”.

 

This would then create your Azure Logic app, which will be available to access in a few seconds.

After the Azure Logic App is created successfully, it would be opened automatically, then you need to select the “Blank Template”. This then opens the Logic App designer canvas where components can be connected to form a flow.

First thing to configure on a Logic App is the trigger. For this example, we will choose “Dynamics 365” and “When a record is created” trigger. This simply means that the Logic App would be triggered when a record is created in Dynamics 365.

 

Once the trigger is selected, it will request you to sign in to your Dynamics 365 instance in order to connect it to the Logic App. Once successfully authenticated, you can configure the trigger.

 

I will be selecting the CRM Organisation and “Notes” as the Entity. Since this Logic App uses a “pull” mechanism, the frequency to process records can be set.

Logic Apps got advanced components where you can check for conditions before proceeding through the flow. For example, once the triggered is configured, you can easily check if the note even contains an attachment of a file; otherwise, you just need to terminate the workflow without progressing further. For this, I used a “Condition” block in Logic apps with a little bit of editing since the field from the trigger returns a Boolean.

Due to limitations in the Logic apps designer, the value you give for the comparison is treated as a string (‘true’ instead of just true). To get around this, I switched the condition to “advanced mode” (you can also use Code View of the logic app but this is a quick way of just customising the condition) where I changed the original condition from:

to:

 

I selected the “Control – Terminate” block when the condition failed, or else perform the rest of the functionality if the condition is met. Within the “Yes” flow, I picked “Azure Blob Storage – Create Blob” action. The action wizard will automatically let you connect to existing Azure storage accounts in your subscription, but if you are connecting to a remote storage account, you can enter the connection details manually.

Once the connection details are configured, you are then presented with additional options.

 

On this dialog, I populated the values using the values that I’m seeing from the trigger such as the File Name & Document content from the note. This is a tricky place to be because the “Document” field contains a Base64 encoded text that contains the actual document content and the Create blob action expects a binary stream. With the code editing power of Azure Logic apps, I can easily achieve a Base64 to binary (byte stream) conversion. To make this happen, click on “Code View” which then presents you with the code version of the logic app workflow.

 

From there, find the “Create Blob” action and replace the “body” field from:

to the below and you are all set.

 

Well, now that we have the file uploading part covered, let’s look at how we can tackle the Note again since the original file is still there. For this aspect, I’m using the “Delete a record” action in Dynamics 365 and “Create a record” action since I can’t modify the same note to not have the actual file. When I’m creating the new note, I’m simply compiling a URL to the file and then saving that in the note body along with any previous description it had.

 

This pretty much concludes the codeless configuration of the Azure logic app. To test this out, you can put the Logic App in “Run” mode by clicking the “Run” button on the toolbar, heading over to Dynamics 365, and uploading a note with a file. You will be able to see the Logic App triggered in real time and see the flow of events it’s processing. Once done, head back to Dynamics 365 again and you will see the new note in there with the path to the file. With Azure Blob storage, there are security aspects that you need to take care of because you can have public and private files in there. So, this is just a quick and easy way of getting this done. For more advanced scenarios, you can still use this template with a bit of tweaking.

Here’s what the above looks like.

Creating the note:

 

The logic app is triggered:

 

Finally, the new note is created in Dynamics CRM with the document’s URL:

 

You might also wonder why I didn’t use “Microsoft Flow” for this. It’s simply because the trigger intervals are much greater, and it doesn’t have the “Code View” feature where you can play with the code. With the features and connectors available within Azure Logic Apps, you can be creative when designing out-of-CRM workflows like this.

Hope you enjoyed this blog post and please reach out if you have any questions.