This project is read-only.

The scenario covered in this project describes how to perform integration between CRM Online and SharePoint Online. The code in this project is based on a Sales Productivity use-case, which is described as follows:
  • When a user moves an Opportunity to the Sales Proposal stage from within CRM, a custom Sales Proposal will be created within SharePoint Online
  • The Sales Proposal will be based on a set of documents needed for the Opportunity, such as budget, contract, etc.
  • The documents will be prefilled with information from the Opportunity, such as name, address, and proposal numbers
The following sections provide information on how to take the source code provided in this project and implement within your own Organization.

Setting up SharePoint Online

Before deploying this solution, you will need to create a new user account within your organization's Office 365 subscription that has administrative permissions within SharePoint Online. This new user will function as a SharePoint Online "Service Account" for the proxy defined below .

Once you have the new user account created, you will need to create a Document Set content type within SharePoint Online. The Document Set should contain a template of fields and default documents that will be associated with the CRM Opportunity. You can also configure "Quick Part" fields within your documents, which will automatically link fields from the Document Set to the documents.

For more information on Document Sets, please visit

CRM Solution

The CRM solution is dependent upon the server-based integration feature released in Spring of 2014 for CRM Online instances to augment document management capabilities for our Sales Productivity scenario with a plug-in. Read more about server-to-server integration between CRM and SharePoint here:

First, we must enable server-based integration within CRM since it is disabled by default. The easiest way to do this is to navigate to Document Management under Settings in MS Dynamics CRM and click on "Enable Server-Based SharePoint Integration" from the options available. In the wizard, paste the URL to the SharePoint site where the folder for your Document Sets will reside (note: this must be an actual SharePoint site and not a document library or document folder).

The other part of this solution is to develop a plug-in and register it in CRM on the Update step for the Opportunity entity. We used the plug-in registration tool provided in Microsoft's Dynamics CRM SDK ( to register the assembly, plug-in and related steps.

The code in our plug-in will need to be updated to gather the information that your web service is expecting. The plug-in has three basic actions:
  • Gather opportunity details relevant for the proposal
  • Pass data to proxy web service
  • Create the required document management records associated with the opportunity
In our example, we use the Dynamics CRM SDK to get field values and retrieve field values from CRM to define five values:
  • Customer Name
  • Customer Address
  • Customer Contact
  • Products
  • Estimated Cost
These values are appended to a dictionary, converted to an array and passed when the web service is called.

After the web service is called, there is a bit of infrastructure that needs to be in place for the integration to work. In MS Dynamics CRM there are two entities that are used for this integration: (1) SharePoint Site and (2) SharePoint Document Location. By enabling the server-based SharePoint integration functionality, CRM automatically creates the SharePoint site record (we went ahead and included it in our plug-in just in case it gets deleted for some reason). There must be a document location record that, when concatenated to the SharePoint site URL, will take you to the root folder that has the opportunity document sets inside and, finally, there must be a document location record for the opportunity itself. The code checks to see if any of this does not exist and fills in the missing pieces.

Required CRM Document Management records:
  • SharePoint Site record for SharePoint site
  • Document Location record for root SharePoint List
  • Document Location record for each SharePoint Document Set (this must be associated with the Opportunity)
Microsoft Azure

For the CRM solution to utilize the advanced functionality available in the SharePoint Online client-side object model (CSOM), an intermediate service proxy is required. This service proxy will take requests from the CRM solution, and generate the necessary SharePoint Online service calls.

Microsoft Azure is used in this example, however, the code is structured so that it can also be implemented within an on premises network. Azure Web Sites are not supported for this demo, and an Azure Web or VM role is required. This is due to a dependency on the SharePoint 2013 Client Components SDK, which need to be installed locally on the system (

The solution is broken up into three projects:
  • AzureSharePointProxyServices - This project contains the Azure web role configuration information, and will need to be updated before deploying to your Azure subscription.
  • AzureSharePointWcf - A C# web project which contains the SaveDocumentSet web service. This project can be deployed to an on premises IIS web server (instead of Azure), as long as the web server has the SharePoint Server Client Components SDK installed (
  • SharePointOnlineServices - This project contains the code which communicates with SharePoint Online, and creates the Document Set. The project can be expanded on with other SharePoint services that fit your organization's needs.
The AzureSharePointProxyServices project contains configuration and deployment information for the Azure Web Role. You will need to modify this with your Azure subscription's information when publishing. One note about this is that the SharePointOnlineServices code provided requires the SharePoint 2013 Client Components SDK to be installed on the web server (copying the assemblies is not enough). To automate this process, a start-up task has been created within the ServiceDefinition.csdef file.

For the AzureSharePointWcf project, you will need to modify the Web.config file before deploying. There are three app settings that must be set before deployment. These are:
  • sharePointUrl - The root SharePoint site for your Office 365 subscription, i.e.
  • serviceAccountUser - The username (e-mail address) of the Service Account defined above
  • serviceAccountPassword - The password for the Service Account defined above

The last code project, SharePointServiceTests, contains all of the source code for connecting to SharePoint Online, creating the Document Set, and setting the parameters that were passed from the CRM Opportunity within it. No changes are needed to this project before deployment.

For more information on Microsoft Azure, please visit

For more information on the SharePoint 2013 Client Side Object Model, please visit

Last edited Dec 9, 2014 at 7:54 PM by jaredhilton, version 24