In this article we are going to talk how Windows Azure Blob Storage can be used with Microsoft Dynamics CRM.
In many of the CRM implementations, we come across requirement where certain documents are required to be linked with records such as accounts, contacts, cases, activities etc. For example –
In cases where these documents are large in number and size, we try to avoid out of box “Attachment” feature of the Dynamics CRM because it rapidly increases the CRM database size. We prefer using some document management solution such as SharePoint, Documentum and integrate with Dynamics CRM. In many cases, the document management solution comes as overhead because –
The Windows Azure Blob Storage is an easy and economical option here. The following are merits of using blob storage in place of document management solution in such scenarios -
What it takes to mingle both?
It is very easy to make both Dynamics CRM and Azure Blob Storage marry. There are well defined and documented APIs for the same. You can custom code integration as per need. I have built a small application (asp.net web application) which can make this integration very simple. The application has a user interface as following –
With this application, you can do the following –
Installation and Configuration of Sample Application
I have attached code of the application in the article. Let me take you through steps to perform installation and configuration of the application.
1. Create Windows Azure Storage Account – First step is to buy Windows Azure subscription and then create windows Azure Storage Account under your subscription. Please refer the following link - http://www.windowsazure.com/en-us/manage/services/storage/how-to-create-a-storage-account/
2. If we try to understand Windows Azure Blob Storage structure in simple terms – A Windows Azure Storage Account can have multiple Containers. Each Container then can store multiple documents and media – each called one Blob. This application creates one container for each record then stores record specific documents and media in this container.
3. I assume you already have Dynamics CRM instance (online or on-premise) ready.
4. Download attached application (asp.net web application) code and make changes to connection strings in web.config file –
<add name="blobstring" connectionString="DefaultEndpointsProtocol=https;AccountName=<STORAGE_NAME>;AccountKey=<ACCOUNT_KEY>"/>
<add name="parentIdentifier" connectionString="<https://CRM_SERVER_NAME>;mainpage.aspx"/>
5. Deploy the application –
6. Integrate with Dynamics CRM – These are two ways to integrate –
a. Using IFRAME – The application has been designed to work by default with IFRAME. It can be configured at entity form level. When you configure the application for an entity, you can then link a document or media to entity record using azure blob as storage. Please perform the following steps for the configuration –
i. Open entity form for customization. It can be any entity such as account, contact, case, order etc.
ii. Insert IFRAME on the entity form.
iii. Set URL of the entity as https://<web_server_name>/mainpage.aspx . The <web_server_name> is the IIS server name or azure web site name where application has been hosted.
iv. Please be sure that you have checked “Pass record object-type and unique identifier as parameters” check box. It is very important to check this because with this setting the record GUID is passed in query string and application uses that to create unique container for the record in the azure storage. Without this setting, the application will not work.
v. Please also ensure to un-check “Restrict cross-frame scripting, where supported” check box. It is another important setting because otherwise application form will not post back and it will throw out into popup when posting back.
vi. Finally save and publish the form customizations.
vii. You can now open entity record and link files to the record. Note: In case of new record, the application will not upload files unless the record has been saved. Remember it needs record GUID to create container for the record in the azure blob.
b. Using Ribbon Button – you can also configure the application with ribbon button but it needs some level of coding. I plan to create a ribbon in next version which will make integration easier. For now – please do the following –
i. Open entity form for customization.
iii. In the application, please open “mainpage.aspx.cs” file and remove the method “CheckReferalPage” and any reference to this method. Please compile and re-host the application.
7. Configure Role Based Access Control – I have not provided any role based access in the application but there are extensions available to easily configure the same. Please do the following –
a. When using with IFRAME –
iii. In the application, please open “mainpage.aspx.cs” file and write role based access behaviour in private method “SetRoleBasedAccess”. Essential, you will read user role names passed and enable\disable control as per access provided to the role.
This is a sample implementation to expedite basic integration of Windows Azure Blob with Dynamics CRM. I am sharing code with you; please feel free to make necessary changes in the code as required. Hope you like this article.