Part 1 of this post covers the CRM-SharePoint (on-prem to on-prem) integration using a custom grid extensively. Anybody can build the integration in a couple of hours with the code snippets and details available in that. If you haven’t read that post, I strongly suggest you go through it before reading this.

This post is an extended version and it’s about how the custom grid to handle SharePoint integration can be added in the left navigation menu of the form rather inside the form itself.

If you aren’t familiar with the keyword, ‘left-navigation menu’, this is what I was talking about.

I understand what you think of now, “Uggh, common man, I use it every day to find the related records”. Yes, it’s the one.

As you can see, the custom page is added to the left navigation menu, let’s see how it’s done. I had removed the default link to ‘Documents’ and add a new navigation link to my HTML i.e. default CRM-SharePoint grid isn’t shown anymore to the user unless there is an error.

Steps to build it:

Step 1: Create a HTML web resource with an IFrame and call the same URL, that points to the Home page (aspx) which we created in the last post.

Step 2: Create a navigation link and add it to the Form to access the created html file.

Step 3: Add PassParams=”1″ to the NavBarItem property of the customization.xml.

Step 4: Providing necessary security role privileges for non-admin users to access the new link.

1. Custom HTML File to render the grid

Below is the HTML code I used, if you observe, Xrm.Page.context.getQueryStringParameters(); is the key method that helps us to the required values, without the changes mentioned in Step 3, this will return NULL value.

If you observe, if there is any error or without enough data, default CRM-SharePoint grid is shown to the user (better to show something and allow users to access the documents than throwing an alert) :).

2. Create Navigation Link to access the HTML file

Open the form that needed the navigation, click ‘Navigation’ as highlighted below and remove the default ‘Documents’ available in the left navigation. Don’t worry, you can add it back any time, it just gets removed not deleted

Click Insert -> ‘Navigation Link’, choose the HTML. It will be added to the left navigation.

Once added, it’s gonna look like this. If wanted to revert, just remove the new link and add the native Documents link.

3. Add PassParams=”1″ to the NavBarItem property of the customization.xml

Yes, it involves manual editing of the solution file but doesn’t need it to worry, it is supported.

Kindly refer this for doing this step. It is explained well by Guido Preite. After the changes, reimport the solution again for proceeding further.

3. Add PassParams=”1″ to the NavBarItem property of the customization.xml

To access the document navigation for non-admin users, give access to the ‘ISV Extension’ privilege under the Customization->Miscellaneous Privileges section. (This guy was the trickiest part and took a while to figure it out).

And that’s all, you got the same grid available in the left-navigation menu now.

Summary

A custom grid is needed to access the SharePoint documents to avoid the famous Chrome issue. It can be added to the Form itself or to the navigation menu as mentioned in this post, whichever the users are familiarized with, go for that.

I know that this is not the hot thing to be discussed in these days where we have fluid integration between latest versions of CRM i.e. Dynamics 365 and SharePoint or D365 with other document management vendors but still this might come handy when your client has the on-premise to on-premise integration between Dynamics CRM and SharePoint.

Note: This is a comprehensive post, within couple of hours, it helps to get the custom grid build for Dynamics CRM – SharePoint integration and handle the document CRUD operations from CRM.

Targeted audience are Developers and Techhnical Consultants. First segment is for Functional Consultants as well.

SharePoint with Dynamics CRM

SharePoint is the obvious choice considering storing the documents and associating it with the Dynamics CRM since CRM isn’t designed to manage the documents. On the other hand, maintaining the documents in SharePoint have advantages like,

Collaboration for non-CRM users to access documents.

Leverage SharePoint document manager features like checking out/check in and version history.

Provides the interface to support OneNote integration with CRM

SharePoint can sync to your Desktop Library and Outlook and other many more.

When we talk about SharePoint integration there are two ways of integration,

CRM List Component – only integration method available for on-premise SharePoint environments as they do not support server-based integration

Server-based SharePoint Integration – Dynamics CRM Server to SharePoint Server (server-to-server) authentication so there is no need to install any additional components.

But why custom grid?

As you know about Chrome’s famous modal-dialog issue which doesn’t allow uploading a new document using the OOB Sharepoint grid in CRM. To give some background, Google Chrome version 35 has deprecated the JavaScript method showModalDialog() and this is a core method used in dialog-return scenarios in Microsoft Dynamics CRM. Not all the client’s are happy with the registry change workaround which will the fix. Refer here for the details.

In this case, where the registry changes can’t be done/not allowed on client’s machine, we can go ahead building a custom page (aspx) and embedded in the iFrame on the form or in the navigation pane.

How it looks?

Once you built, it looks like this (of course, depends on the style you use).

Using jQuery block UI on load to show a custom message with loader for better user adoption. Note: You can have your custom styles as well instead of block UI and have used the same .gif that CRM uses.

2. View list of documents under a tab:

3. On deleting the selected documents, you can have the custom messages and on confirmation delete the file and route to the same page with the valid query string parameters.

4. Upload page with just a file upload control and a couple of buttons. On Submit, the document is uploaded to the SharePoint, shows a confirmation alert and the popup and window are closed.

Steps to build it:

Design the Home page (aspx) with grid and buttons to Add, Delete and Edit if needed.

In the code behind, the grid view is populated by the data retrieved from the SharePoint. To retrieve the files from the SharePoint, document location details (available within CRM) of that specific record needs to retrieve. To understand how SharePoint Document Locations work, refer to Debajit’s blog.

3. SharePoint Interfaces

This segment has the key logic for the CRUD operations for the SharePoint documents.

Upload a new document to SharePoint:

SharePoint’s elevated credentials is used for impersonation to do the operations but the actual user’s name should be seen in the grid’s Uploaded By and Modified By colums respectively. To achieve that, the current CRM user’s name is updated back to the SharePoint’s Author and Editor fields immediately after a successful upload.

Once you got the aspx page built, just call it from the CRM form, bingo!

4. JavaScript (web resource) to get the required data and set it to the iFrame (pass it to the aspx page)

The web resource is added in the Form and triggered by the expansion of the Tab. The script will retrieve the relevant data, in my case, it was the entity’s schema name and guid and pass it to the iFrame.

The OOB SharePoint grid in CRM created a SharePoint folder when you navigate to the Documents area from the from navigation but in our case, since we are using a custom page, it is our responsibility to create a SharePoint folder. We are creating a SharePoint folder when the record is created in the CRM in Plugin.

5. Plugin – to create a folder in SharePoint on the creation of a record

Create SharePoint document location in CRM if not available

if (_spDocLocId == Guid.Empty)
{
//There is no location so create one
_spDocLocId = CreateSharePointDocLocation(orgService, FolderName, entityID, entity.LogicalName, entityDisplayName);
//Get the abslouteURL from the doc location just created
string absouteUrl = GetAbslouteUrl(orgService, _spDocLocId);
// We still need to create a SharePoint folder
CreateSharePointFolder(absouteUrl, entityDisplayName);
}