Part-1: Azure BLOB storage with Dynamics 365 for operations

With the Introduction of cloud based applications, Dynamics has opened doors for seamless integration with Azure services. This blog is created to portray one such example of how Azure capability can be utilized within Dynamics 365 for Operations.

Lets consider a common scenario where Dynamics 365 for Operations needs exchange of files between different applications. This can be a file produced by your .Net application (or) it can be a file produced by you production system,etc,. In Dynamics AX 2012 this situation was handled by creating common folder and sharing in network path where different applications can place their files. Upon introduction of D365, local paths were not accessible by Dynamics production URL so we need to rely on common internet service for accessing the file.

One of the convenient way to handle this situation is by using Microsoft Azure BLOB storage as the central repository to exchange files between different external systems. Using Azure BLOB as storage space now Dynamics 365 and other external applications can send files or consume files. Since we have the files in Azure, this can be easily accessible by Cloud API’s provided by Azure.

Part-1: Creating Azure BLOB and establishing connection within Dynamics 365 for Operations

This blog series is created as 3-part series to explain how Dynamics 365 for Operations X++ code can be utilized to perform different operations with Azure blob files:

Part-1: Creating Azure BLOB and establishing connection within Dynamics 365 for Operations Operations

Part-2: Consuming files stored in the Azure Blob Storage within Dynamics 365 Finance and Operations using X++ code

     a. Get list of file names stored in the blob.

     b. Get the memory stream of each files stored in the azure blob storage.

     c. Read the content of the file line by line.

Part-3: Azure Blob Upload file, Move file and Delete file in Dynamics 365 Finance and Operations using X++ code


Part-1: Creating Azure BLOB storage and establishing connection within Dynamics 365 for Operations

Before we proceed, we must make sure the following details are created.

1) Create Azure Block BLOB Storage account and blob container in Azure portal

Please refer to this Link for more details.

In our example, below is the Blob created.                    

     Storage account name: sccblobstorage

     Blob container name: sccblobcontainer

2) Store the connection string in D365 FNO

Your application needs to access the connection string at runtime to authorize requests made to Azure Storage and so you can store the connection string in D365 FNO environment variable (e.g. A field in a parameter form).

The format of the connection string is

DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey

Indicate whether you want to connect to the storage account through HTTPS (recommended) or HTTP, replace “myAccountName” with the name of your storage account, and replace “myAccountKey” with your account access key.

The connection string for the storage account can be found in the Azure portal.  

3) Blob container name

Note down the container name where the files are stored. In our example, the container name is “sccblobcontainer”

4) Store the Blob file path in D365 FNO

The blob container has a folder-like structure and files have to be accessed in a certain path. To access the file at a particular location, the file path is required and stored in the D365 FNO environment variable. Using this file path, you can iterate the blob container to a particular folder and access the files.

File path can be stored for below example as: “SainaCloudConsulting\Test1”

File name: TestFile.txt


Establish a connection with the blob container

In Dynamics 365 for Operations, connection to the BLOB can be established with the help of following class libraries: 

  • CloudBlobClient – Establishes client usage of Azure BLOB storage
  • CloudBlobContainer – Enables access to created container
  • CloudStorageAccount – Establishes connection to cloud storage account 

Here is the complete code for getting BLOB connected using Dynamics 365 for Operations:

  1. CloudBlobClient  cloudBlobClient;
  2. CloudBlobContainer  cloudBlobContainer;
  3. CloudStorageAccount  cloudStorageAccount;
  4. cloudStorageAccount  = CloudStorageAccount::Parse(“DefaultEndpointsProtocol=https;AccountName=sccblobstorage;AccountKey=K/X1oQfY30ZmYnl9s89545409jhtvnkbCvJzX7HWa+Bg==;EndpointSuffix=core.windows.net”);
  5. cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
  6. cloudBlobContainer  = cloudBlobClient.GetContainerReference(“sccblobcontainer”);