Friday, September 09, 2016

Showing SharePoint document properties in Dynamics CRM views

As outlined in a previous blog post, Dynamics CRM provides out of the box integration with SharePoint – meaning that you can upload your documents into SharePoint directly from within the CRM user interface and link them to specific CRM records (See Using SharePoint Online to store Dynamics CRM Online documents for more details). This same integration scenario is also available for Dynamics CRM on-premise and SharePoint Server on-premise deployment.  From Dynamics CRM 2016 onwards it is also possible to use hybrid integration scenarios where as outlined in Setup SharePoint Integration with Dynamics CRM

The preferred method for integration is using Server-to-server integration (See Integrate Microsoft Dynamics CRM CRM with SharePoint) but there are some noticeable differences between the Dynamics CRM List component and server-based SharePoint integration as outlined in Important considerations for server-based SharePoint integration as well as SharePoint Integration Reloaded Part 1 from Scott Durow. From Dynamics CRM

 One of the great features which is enabled using server-based SharePoint integration is the fact that you are also able to show fields (or site columns) which are added in SharePoint within the Documents view in Dynamics CRM. Site columns or library columns (also referred to as fields or attributes) are used to organize documents so that people can find back the documents they need more easily. Document libraries in SharePoint are like real libraries where you can borrow books, a library has a system in place to search for the books by publication year, author, language, genre, age category, etc… In a SharePoint document library you would use site columns or library columns which would contain this information. This is also called metadata – “data (information) that provides information about other data”.  So if you enable document management on the Account entity in CRM using server-based-integration it would look like the screenshot below.  
 Dynamics CRM uses a number of entities to enable the integration with SharePoint :
  • SharePoint site (schema: SharePointSite): represents a location record in Microsoft Dynamics CRM that points to a site collection or a site on a server that is running SharePoint Server (See SharePointSite entity messages and methods )
  • SharePointDocumentLocation : represents a location record in Microsoft Dynamics CRM that points to a document folder on a server that is running SharePoint Server. You can associate the SharePoint document location records in Microsoft Dynamics CRM with the entity records for the entities for which the SharePoint Server integration or document management feature is enabled. (See SharePointDocumentLocation entity messages and methods)
  • UserMapping : represents a custom claim mapping record in Microsoft Dynamics CRM to use a value other than the default value used by CRM Online for authenticating and authorizing CRM users in SharePoint (See UserMapping entity messages and methods)
Next to these three entities which are documented by Microsoft there is a 4th entity SharePointDocument which is actually quite an important entity since it is in the SharePointDocument entity that you can define additional SharePoint columns that you want to be displayed in the grid. Internally CRM will translate the FETCHXML query to a SharePoint query (CAML – Collaborative Application Markup Language ) – if you are interested to know how this is done you can use JustDecompile and take a look at the code in the Microsoft.CRM.ObjectModel.dll which apparently has the implementation code for the SharePoint integration.


If you look at the SharePoint Document entity in CRM and check out the list of fields you’ll see there are quite a few fields (such as Title, version, etc..) that you can display. These fields will display the corresponding values from columns in a SharePoint document library if you add them to the SharePoint Document Associated View. So for example you can quite easily make the title of a document in SharePoint appear in the CRM view.

This is great for the out of the box fields but if you have modified the library in SharePoint to add additional attributes you’ll notice they are not displayed. So let’s image that you have added a custom field called DocType (of type text) in a SharePoint document library as shown below and you want to show the values of this SharePoint column in Dynamics CRM (I suppose that you already setup with document management integration already setup). You will need to perform a number of steps to accomplish this: 
  • Create a new solution in Dynamics CRM (you can also use the Customize the system option but this is not really the recommended way)
  • Add the SharePointDocument entity and the Document Associated Grid to your CRM solution

  • Navigate to the SharePoint document library that is used to store the documents linked to your CRM record and add a column of type text with name “DocType”.
  • Add a field on the SharePointDocument entity with exactly the same display name “DocType” of type single line of text. Dynamics CRM will use the display name of the fields to do the mapping with the query which is send to SharePoint. All values returned from SharePoint will be of type text except for a date field in SharePoint. So you need to create fields of the corresponding type in CRM.
  • Modify the “Document Associated Grid” view that you added to your CRM solution and add the newly created CRM field to this view. (This will only work with the “Document Associated Grid” view – to make this work with new views you will need some extra steps that I will outline in a next blog post)

Once you fill in the values of the SharePoint fields for the different documents you will notice that they appear in the CRM “Document Associated Grid” as well. This seems to work for the following types of SharePoint fields: text, number,date,choice, boolean,currency and person. I currently only tested the scenario in Dynamics CRM Online (8.1.0.452) in combination with SharePoint Online as well as for Dynamics CRM 2016 (Update 0.1) on premise in combination with SharePoint Server 2013 but I guess it should also work in other setups which are using server-based-integration.



References:





5 comments:

  1. Anonymous12:17 PM

    First of all - Thank you so much for this post, we have a custom sharepoint integration in dynamics 2011 with the list control and I've been scratching my head as to how to go about approaching a 2016 conversion with server side sync. That said I have followed your instruction on adding meta data to the associated view and it does not pull my meta data back. Also if I sort on the meta data field it errors. I am using dynamics 2016 SP1 and sharepoint online, any ideas? do i need to set anything in particular in the simple text field in CRM? IME mode etc? Do i need to publish in some way on sharepoint before the REST API recognises the new metadata field?

    ReplyDelete
  2. I've tried this as well (on-premise CRM and Sharepoint 2016) and get the same results as the other commenter - no data pulled for the custom column, and an error if I sort by it. If there's any potential additional steps or gotchas you can think of (or ways to test what the problem might be), I'd really appreciate it! Thanks! :-)

    ReplyDelete
  3. Hi Allison, which version of CRM on-premise are you using? Do you see some errors in the CRM logs or in the SharePoint Server logs?

    ReplyDelete
  4. greed9212:29 PM

    Hello,
    I'm in the same situation of Allison. The error is that the "key" cannot be a NULL value (in the CRM Trace says it when it try to get the FormatedValue from the ListItem of SP). In SharePoint all the "custom" columns are correctly filled with some value (they are all strings, both in CRM and SP). The display name in CRM and the internal name in SharePoint are the same.

    In my case we have a CRM2016 OnPremise and SharePoint Online.

    Thank you in advance.

    ReplyDelete
  5. For the moment I have only tested this scenario with a combination of SharePoint Online and Dynamics 365 (Online) as well as using both CRM and SharePoint on premise (but still using SharePoint 2013). Maybe also check the SharePoint ULS logs to see if there is a more descriptive error in there.

    ReplyDelete