Share This Post

MSD CRM Updates

Custom Upload to SharePoint in Dynamics CRM

While Microsoft Dynamics CRM offers integration options and features available with SharePoint On-Premise/ Online, there are some cases where doing the SharePoint Integration is not worth setting up.

Dynamics CRM SharePoint

Dynamics CRM SharePoint

Creating a SharePoint Folder for a CRM record using the SharePoint REST API which was generating a link to upload a Document to a SharePoint Document Library from CRM.

Add a document

Add a document

Default Upload Button in Library vs. Upload Form

Upload

Upload

On every Document Library in the Dynamics Customer Relationship Management SharePoint, there is an Upload button available which essentially uploads a Document under that Library.

While this directs the user, on click, to the Document Library so that they CAN upload a document under this Folder. This is essentially an in-built Upload form that is linked to a specific Document Library and allows the user to select the File they want to add under the Library. While this doesn’t save the user any clicks compared to opening the Document Library in the Dynamics Customer Relationship Management SharePoint and clicking the ‘Upload’ button (screenshot above), we want to explicitly guide the users on including the Document and direct them straight from CRM.

Making the Button

upload documents

upload documents

First, we need to construct a custom Ribbon button, which I’ve labeled ‘Upload Documents’. I’ve constructed this using Ribbon Workbench. This button then calls the JavaScript Web Resource that will open the Upload URL for that particular CRM record.

Constructing the Upload Form URL

In the Web Resource, what we are essentially doing is constructing a URL.

http://yourServer/sites/yourSite/_layouts/15/Upload.aspx?List={Site GUID}&RootFolder={Relative URL}&Source={URL to Navigate}&IsDlg=1

The link has the below data which you need to set in your Web Resource when constructing a working URL.

  • The number/15/ is the version of SharePoint.
  • List = GUID for Document Library.

In order for me to obtain the GUID:
1. Navigate to Site Settings.
2. In the Site Settings, under ‘Site Administration’, go to the ‘Site libraries and lists’.

site settings

site settings

3. In the Site Libraries and Lists, go to the Customize Documents.
4. Step 3 will directly take you to the Site’s Document Settings page. Obtain the GUID for the Site in the URL:

GUID

GUID

  • RootFolder = the Folder in the Library. This is optional.

Note: Don’t worry about the spaces when constructing your link in the JavaScript. The spaces get replaced with %2F when it is opened in the browser.

  • Source = the URL to navigate to after the upload is complete. This is optional. This depends on your requirements. You can set this to the upload the URL such that a user can recursively upload another Document after an upload.
  • IsDlg = controls if the upload form is shown as a popup or a full page. Set this to 1 for the popup, or leave this off in your URL for a full page.

    &IsDlg=1

    Once you’ve obtained all the relevant data, you now just need to construct your URL in the JavaScript Web Resource.

JavaScript Web Resource

JavaScript Web Resource

In the screenshot shown above, for the demonstration purposes, I hardcoded the values.

It is not recommended for you to hardcode the values in your JavaScript code. Recommended methods you are able to dynamically store these in CRM and obtain these values in JavaScript are either through:
• A custom Settings entity. These add values which are used commonly by all my URLs i.e. the SharePoint Base URL, Site Relative URL, and the Site GUID.
• The specific CRM record itself. These are values which are mention to the CRM record such as the record relative URL (to be placed after &RootFolder=)

Share This Post

Leave a Reply

avatar
  Subscribe  
Notify of
Skip to toolbar