Posted on 11. November 2010

CRM 2011 Document Management in SharePoint

Integration between Dynamics CRM and SharePoint has been possible since version 3.0 but involved custom extensions that often proved tricky to maintain. Dynamics CRM 2011 now provides SharePoint integration out of the box.

This post provides a summary of this new integration with SharePoint 2010.

Essentially the integration allows you to create a folder for each entity type (where document management is enabled), and sub folders to store documents relating to a specific record. Using SharePoint 2010, Dynamics CRM 2011 will automatically create these folders for your having the same name as a particular record. To utilise this automatic folder creation, a SharePoint site is set as the default location, and then for each record folder a 'Document Location' record is automatically created. These Document Locations can also be created manually on a per record basis to point to a folder by a absolute URL in any SharePoint site, or by using a relative URL relating to an existing Document Location.

To Set up Document Management in Dynamics CRM 2011:

1) Select System->Document Management->Document Management Settings.

2) In the Document Management Settings Dialogue, select the entities that you wish to enable Document Locations on.

3) Select the Url of the SharePoint site that you want to store documents in by default. Users have the option of adding more locations manually on a per record basis, but this site is the default that will be used.  The default site can be changed later if it becomes full or changed if it has moved - if a new default location is created, new document locations will use the new site, but existing document locations will still be linked to the old site.

4) Click Next

5) In the next dialogue, the SharePoint site is validated. If you select 'Based on entity' you can select the sub folder to store documents underneath.
For example, if you create a document location for a contact 'Joe Bloggs', and then create a case for Joe, and then select 'Documents', a document location will be created underneath the Joe Bloggs document folder. So the folder structure will be:

SharePoint Site/contact/Joe Bloggs/incident/Broken Printer

Interestingly, if you don't have a folder for the contact before you create the case and select 'Documents', the contact folder will not be used, and you'll have:


SharePointSite/incident/Broken Printer

6) By Clicking 'Next' you'll see a message box asking you to confirm that you want to create the root document locations for each entity.

7) Clicking Ok, will give you a progress window, where each folder is created in SharePoint. You must have permissions to the given SharePoint site to create folders otherwise the process will fail.

At the core of the integration there are two new entities:

SharePoint Site - Provides a link to a SharePoint site collection or site.

It has the following attributes:

  • Name - The Name of the SharePoint site. This is set automatically to 'Default Site Collection', or 'Default Site'.
  • Description
  • Url Type - Picklist - Absolute/Relative
  • Parent Site - Lookup - If the Url Type is Relative, this references the parent Site or Site collection
  • Relative Url - Text - If the Url Type is Relative, this provides the sub site location.

Document Location - Provides a link to a document library and folder for a given record. E.g. If you click on 'Documents' in the navigation bar, a folder is created with the same name as the record.

It has the following attributes:

  • Name - The Name of the Location. By default this is of the structure 'Documents on <Site Name> #' Where # is an incremental counter. This can be renamed once created.
  • Description
  • Url Type - Picklist - Absolute/Relative
  • Absolute Url - The
  • Parent Site
  • Relative Url - The folder name where documents are stored. It cannot be more than one folder, so if you have nested folders, you must create a parent Document Location, and reference it in a sub Document Location.
  • Regarding - Empty for root document folders (contact, account, incident etc), and for specific record folders, the lookup field references the specific record that the document folder is associated with. Essentially this is the same as the 'Regarding' field on activities.

So if you enabled document management on contacts and incidents, you would end up with the following Document Libraries:

Name

Parent Library /Location

Relative Url

Regarding

Documents on Default Site Collection 1

Default Site Collection

contact

 

Documents on Default Site Collection 2

Default Site Collection

Incident

 

Scenario 1 - A contact with 1 case with the 'Based on entity' unchecked.

Name

Parent Library/Location

Relative Url

Regarding

Documents on Default Site Collection 1

Default Site Collection

contact

 

Documents on Default Site Collection 2

Default Site Collection

Incident

 

Documents on Default Site Collection 3

Documents on Default Site Collection 1

Joe Bloggs

Joe Bloggs

Documents on Default Site Collection 4

Documents on Default Site Collection 2

Broken Printer

Broken Printer

Notice that the parent library/location for the contact and case is set to the root document location that was created by the Document Management Settings wizard.

Scenario 2 - A contact with 1 case with the 'Based on entity' is checked.

Name

Parent Library/Location

Relative Url

Regarding

Documents on Default Site Collection 1

Default Site Collection

contact

 

Documents on Default Site Collection 2

Default Site Collection

Incident

 

Documents on Default Site Collection 3

Documents on Default Site Collection 1

Joe Bloggs

Joe Bloggs

Documents on Default Site Collection 4

Documents on Default Site Collection 3

incident

 

Documents on Default Site Collection 5

Documents on Default Site Collection 4

Broken Printer

Broken Printer

Notice that the broken printer case document folder is created underneath the contact folder:

Contact/Joe Bloggs/incident/Broker Printer
  • Figure 1 - UML representation of CRM 2011 SharePoint concepts

    The actual interface to SharePoint is provided by the CrmGrid page that must be installed on the SharePoint server. The installation notes provide good instructions on how to get it installed: http://go.microsoft.com/fwlink/?LinkID=200050.

    Because the SharePoint integration is an Iframe, the client security context of the current user is used and so you must have access to the SharePoint site to perform operations from within Crm. There is no linkage between CRM and SharePoint Security.

    When you click on 'Documents' inside an entity form, you will be prompted with:

    Clicking Ok, will create the document folder, and document location record. The document library view inside CRM looks like:

  • You can select from multiple locations associated with the same location using the Document Locations drop down.

    If you fill up your default site, you can add a new SharePoint Site through the Document Management Settings->SharePoint Sites list, and select 'Make Default'

     

    Notes:

    1) Since the folder in SharePoint is named using the display name of the record, if you subsequently change the name in CRM (e.g. change the name of the contact, or rename the title of the case) you will receive a 'library not found' error when clicking on the 'Documents' navigation bar item. CRM 2011 then gives you the option to re-associate the record with a new location. This usually would mean renaming the folder in SharePoint and then updating the document location record in CRM.

    2) There is no synchronisation between the security roles in CRM and those in SharePoint. For this reason you must secure your SharePoint site manually. If a user attempts to use the automatic folder creation feature, but they don't have access to the SharePoint document library, the operation will fail.

    3) Some CRM 4.0 integrations to SharePoint allowed you to create a sub-site per entity record. This would still be possible with the CRM 2011 integration with some coding, since you can create your own document locations and relate them to the given record. A Plug-in could be created to automatically create a sub-site and create a corresponding SharePoint Site and Document Location when a record is created. Since the default site folder creation only runs if there are no Document Locations for the current record, you would then simply be given the custom document location rather than a default one created.

    4) Note attachments and email attachments are still stored in the CRM database, and currently there is no easy way of removing the ability for uses to create attachments in CRM without removing notes all together. Email attachment support is tightly coupled to the CRM database storage of documents, and so this is always going to be needed. A custom plugin could be written to 'harvest' note/email attachments and automatically add them to the associated document location.

    5) If you enable Content Types on your document libraries, when you add a document via CRM, since the interface is essentially just SharePoint, you are still promoted to select the Content Type and provide additional metadata.

    6) The automatic folder creation functionality is only available when you are connecting to SharePoint 2010, although Document locations will work with SharePoint 2007.

    Conclusions

    The out of the box support for SharePoint in Dynamics CRM2011 does a good job of providing a simple and low maintenance option for users to store and retrieve documents in SharePoint  from within Dynamics CRM records. Users can then benefit from SharePoint's searching and document management features. More importantly, it is designed in such a way that it can be extended by Developers to support more complex integration scenarios.

    Posted on 11. November 2010

    Export Dynamics CRM Plugin Assembly

    Have you ever uploaded a Dynamics CRM Plug in and then later wanted to get the assembly that was uploaded? The following steps are to modify the Plugin Registration Tool found in the CRM SDK to allow export of assemblies once they are uploaded.

    1. In the file OrganisationHelper.cs

    Modify the GetColumnSet method

    case PluginAssembly.EntityLogicalName:
    // Develop1:Download Assembly Support
    cols.AddColumns("name", "createdon", "modifiedon", "customizationlevel", "pluginassemblyid", "sourcetype", "path", "version", "publickeytoken", "culture", "isolationmode", "description","content");
    

    2. In the file CrmPluginAssembly.cs

    Add the following code to the class:

    // Develop1
    private string _content;
    public void ExportAssembly(string path)
    {
      byte[] assembly = Convert.FromBase64String(this._content);
      File.WriteAllBytes(path, assembly);
    }
    

    3. In the file CrmPluginAssembly.cs

    Add the following code at the end of the RefreshFromPluginAssembly method:

    // Develop1:Download Assembly Support
    if (assembly.Content != null)
    {
        this._content = assembly.Content;
    }
    

    4. On the PluginRegistrationForm Form

    Add a button next to the Load Assembly command button with the following properties:

    Text: Export Assembly

    Name: cmdExport

    5. Double click on the button to get to the event code:

            // Develop1:Download Assembly Support
            private void cmdExport_Click(object sender, EventArgs e)
            {
                this.m_currentAssembly.ExportAssembly(txtAssemblyPath.Text);
              MessageBox.Show("Assembly exported.");
            }
    

    To use, you'll need to double click on a plugin assembly to bring up the properties page. Enter a file path (e.g. C:\ExportedAssembly.dll) Ddon't use the browse button since this wlll load an assembly. Click 'Export Assembly' to export your assembly.

     

    Posted on 11. November 2010

    Have you tried turning it off and on again?

    Today I was trying to register a Plugin to Dynamics CRM 2011, and I received the following error:

    System.Runtime.InteropServices.COMException: Microsoft Dynamics CRM has experienced an error.
     Reference number for administrators or support: #63F08CDB

    Using the platform trace, I tracked it down to the following exception:

    System.Runtime.InteropServices.COMException (0x800703FA):
    Retrieving the COM class factory for component
    with CLSID {E5CB7A31-7512-11D2-89CE-0080C792E5D8}
    failed due to the following error: 
    800703fa Illegal operation attempted on a 
    registry key that has been marked for deletion.

    From further digging, this turned out to be an issue to do with the installer having deleted a COM registration, but the registry hive not yet unloaded due to user locking it. To fix, I simply re-booted. Just goes to show you - as that great philosopher Roy Trennaman once said
    'Hello, IT, have you tried turning it off and on again?'

    Posted on 11. November 2010

    Server Error in Application "MICROSOFT DYNAMICS CRM" HTTP Error 404.0 - Not Found

    After installing a CRM 4.0 ISV Add-on to my Dynamics CRM 2011 Beta 1 server (foolish I hear you say!), I was presented with the following:

     

    Server Error in Application "MICROSOFT DYNAMICS CRM"Internet Information Services 7.5

    Error Summary

    HTTP Error 404.0 - Not Found

    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

     

    It seems that the IIS7 CRM Application pool had been modified to revert back to using the version 2 framework. To resolve:

    1. Open IIS 7 Manager

    2. Navigate to the CRMAppPool and double click on it to enter the Basic Settings.

    3. Change the Framework version to be v4:

     

    Posted on 2. November 2010

    Windows Phone 7 and Windows 7 auto answering calls

    Having recently upgraded to a Windows Phone 7 HTC HD7, I paired the phone with my laptop via Bluetooth.

    Imagine my surprise when a call came in that it was auto answered, and my laptop was acting as a hands-free headset! 

    To prevent this from happing:

     

    1. From within Windows 7 on your Laptop/PC, open up 'Devices and Printers'
    2. Use the context menu on your phone, and select 'Properties'
    3. Open the 'Services' tab and un-check A2DP and Headset Audio Gateway.
    4. Click 'OK'

     

    Hope this avoids some frustration!

     

    Posted on 2. November 2010

    KB2439176 - for Dynamics CRM 2011 Beta 1

    If you chose to use Windows Update for your installation of Dynamics CRM 2011 beta 1, recently you will have been prompted with the option to install KB2439176. This changes the version:

     

    • 5.0.9585.106 Beta 1
    • 5.0.9585.110 Beta 1 with KB2439176

     

    There appears to be little or no background on what this update includes - I've had no problems so far.

    You can see all updates here:

    http://catalog.update.microsoft.com/v7/site/search.aspx?q=crm

     

    Posted on 2. November 2010

    You have already imported and upgraded this organization

    Since importing CRM 4 customisations xml is not possible with Dynamics CRM 2011 Beta 1, using the import organisation wizard is the only option. During development, I’ve found that there is no way of importing and upgrading a CRM 4.0 organisation more multiple times. Once you import and upgrade a CRM 4 organisation, the OrganisationId is retained in the database (rather than a new one being assigned as for when you import a CRM 2011 organisation database), so importing and upgrading the same organisation results in the error "You have already imported and upgraded this organization". Even if you delete the previous import, the import still fails.

    To get around this I used the following steps:

    Warning: I'm doing this a development environment, and this is something that you would never do in production. Also, always make a backup first.

    1. Disable and Delete the previously imported organisation using Deployment Manager

    2. Run the following script against the MSCRM_Config database. Replace 'YourOrgName' with the name of the organisation you used when importing the first time.

    -- Remove a previously imported and upgrade organisation
    DECLARE @orgName nvarchar(255) ='YourOrgName' 
    DECLARE @organisationid uniqueidentifier
    SELECT @organisationid=ID from Organization WHERE UniqueName=@orgName
    DELETE FROM SystemUserOrganizations where OrganizationId=@organisationid
    DELETE FROM OrganizationProperties where ID=@organisationid
    DELETE FROM OrganizationFeatureMap where OrganizationId=@organisationid
    DELETE FROM OrganizationMaintenanceJobs where OrganizationId=@organisationid
    DELETE FROM Organization where ID=@organisationid
    
    
    

     

     3. Re-import the organisation using Deployment Manager