Microsoft Dynamics CRM Version 4.0 Contextual Document Libraries
For Microsoft Dynamics CRM 4.0 we will create a post-create plug-in that will create a contextual document library within SharePoint whenever a new Account record is created. SharePoint provides us with web services that allow us to programmatically create document libraries. The code sample also then writes the URL of the document library to custom attributes in the Account entity. The contextual document library is displayed in an iFrame by some custom JavaScript in the onLoad event for the Account form in Microsoft Dynamics CRM.
Steps to follow:
Step 1: We need to add a custom attribute to the Account entity, these attributes are used to store the location of the contextual document library URL and folders that we create via the plug-in. Create the following attribute for the Account entity:
New_sharepointdocumentlibraryurl: nvarchar – allow a reasonable length for the URL (300) value
Step 2: Save the changes
Step 3: Publish the changes so that the CRM web services are up to date with our new attributes.
Step 4: Create a class library project in Visual Studio to create our CRM 4.0 Plug-In component for the Account Create transaction (call project – AccountCreatePlugin and rename cs file to UpdateAccountCreate.cs.
Step 5: Add a web reference for SharePoint (call it SharePoint), typically this is lists.asmx and there may be a number of these web service endpoints due to multiple SharePoint sites on your designated server. SharePoint is designed so that the web services are virtualized at every site level. All of the web services binaries are located in the /_vti_bin directory. For example: http:///_vti_bin/lists.asmx (http://localhost:7777/)
Step 6: Add references to the following dll’s: Microsoft.crm.sdk.dll and Microsoft.crm.sdktypeproxy.dll, these are found in the bin folder where you have unpacked the crm sdk. Add another reference to into your project.
Step 7: Ensure you are editing the main class file in your project.Look through this code and make sure you change any System.Net.NetworkCredential to a valid username, password and domain (this has already been completed for you). Also look through the code for any references to yoursharepointservername and change this to a valid server name for your SharePoint location (this has already been completed for you). Add the code below to your class file
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using AccountCreatePlugin.SharePoint;
using System.Web.Services;
namespace AccountCreatePlugin
            public class UpdateAccountOnCreate : IPlugin
                        #region IPlugin Members
                        public void Execute(IPluginExecutionContext context)
                                    //First we’ll grab the name of our account and its GUID
                                    DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
                                    string accountName = entity[”name”].ToString();
                                    string accountId = context.OutputParameters.Properties[”id”].ToString();
                                    //SharePoint Document Libraries have a type code of 101
                                    Int32 spDocLibraryListType = 101;
                                    //Call the SharePoint Web Service to create a document library
                                    Lists listService = new Lists();
                                    listService.Credentials = new System.Net.NetworkCredential(”administrator”, “pass@word1″, “litwareinc”);
                                    System.Xml.XmlNode SPresult = listService.AddList(accountName, accountName + ” Document Library”, spDocLibraryListType);
                                    //grab the return xml
                                    string returnXml = SPresult.InnerXml.ToString();
                                    //Now we’ll update our account record with the URL of the contextual SP library
                                    DynamicEntity account = new DynamicEntity();
                                    account.Name = EntityName.account.ToString();
                                    account[”accountid”] = new Key(new Guid(accountId));
                                    account[”new_sharepointdocumentlibraryurl”] = “http://localhost:7777/” + accountName + “/Forms/AllItems.aspx”;
                                    //Using the iPlugIn interface we create a reference to the CrmService web service
                                    ICrmService service = context.CreateCrmService(true);
Step 8: Sign your dll
}Step 9: Compile your new plug-in component.
Step 10: Copy the compiled plug-in assembly AccountCreatePlugin.dll to the \Server\bin\assembly folder of your Microsoft Dynamics CRM server.  
Step 12: Register this plug-in with the platform – this is available from Tool in VS (see SDK for more info). You can either register this synchronously or asynchronously
Step 12 a: Register Step with the platform (message = create, entity = account) then register
Step 13: We now need to configure the iFrames in the Account entity to display our contextual document libraries or folders. Add a new tab called Document Library and then add a new iFrame called IFRAME_SharePoint
Step 14: Next we want to add in the OnLoad logic on the Account form to set the URL of the SharePoint iFrame to display our contextual document library.
// OnLoad Event to set the iFrame URL for the SharePoint Library.
// Set SharePoint Document Library
// we’ll update the iFrame src property if this is an update form
if (crmForm.FormType == CRM_FORM_TYPE_UPDATE)
var sUrl=crmForm.all.new_sharepointdocumentlibraryurl.DataValue;
crmForm.all.IFRAME_SharePoint.src = sUrl;
Step 15: Save the changes to the Account Entity.
Step 16: Publish changes
Step 17: Create a new account record



(1) Open Internet Explorer.


(3) Choose the “CUSTOM LEVEL” button.

(4) Within the Settings change “USER AUTHENTICATION” to “Prompt for user name and password”

(5) Choose OK >> APPLY.

(6) Close Internet Explorer.

The next time you go to log into CRM via the Internet Explorer, you should be prompted to enter in your username and password.



Microsoft Corp. today announced that Profiles International Inc., which provides Web-based employee-assessment and talent management solutions to companies across the globe, has chosen Microsoft Dynamics CRM to replace its Pivotal CRM software.

The new Microsoft technology replaces the company’s CDC Software Pivotal CRM, Pivotal ePartner portal, Pivotal MarketFirst electronic marketing application and basic intranet site.  Profiles International evaluated software from Oracle’s Siebel,, SAP, Sage CRM Solutions, Netsuite Inc. and CDC’s Pivotal before selecting the Microsoft Dynamics solution.          

For more information on this visit: [Microsoft PressPass]