Using JavaScript to connect CRM and SharePoint

Marc Whitlow, 05 December 2011

I have recently been working on a project where the client requested that their Activities in Dynamics CRM are displayed in SharePoint 2010. However, there was a catch. The projects which exist in SharePoint 2010 and the Projects Entity in Dynamics CRM 2011 have no logical connection therefore the only connecting aspect was the name.

  Using JavaScript to connect CRM and SharePoint

To overcome this problem I developed a work around which could be used to make the connection. Because each project record had a “Name” field which was the title of the project I could easily make the connection to SharePoint, as every new site In SharePoint had a site name which was the Project Title.

To get the Dynamics CRM Entities into SharePoint I utilised the “List Web Part for Microsoft Dynamics CRM 4.0”. This Web Part is developed for CRM 4.0. However the one version backwards / forwards compatibility of Microsoft Dynamics CRM’s made this the perfection solution.

To install the web part I simply added a new web-part to the page.  Click on “Add a Web part” then Select the web-part from the “Miscellaneous” tab as shown below.

Using JavaScript to connect CRM and SharePoint 

After installing the Web Part on the SharePoint Site I configured the settings so the web part was retrieving the Activities entity. Inside the CRM server I created a new view. In this view I configured only the Subject, Activity Type, Regarding and Owner field to be seen. But remember! You MUST click “Publish All Customisations” for your changes in CRM to take place.

 Using JavaScript to connect CRM and SharePoint

When configuring the Web Part deployment in SharePoint I simply selected the new view I had created as shown below.

 Using JavaScript to connect CRM and SharePoint

To show only the activities regarding that project I simply used JavaScript in a separate web part which was placed below the crm web part. I used “document.getElementById(‘id of site title’); to first get the site title.

 Using JavaScript to connect CRM and SharePoint

From here I assigned this title to a variable named “var siteTitle”.

Next I again used “document.getElementById(‘searchInputId”);. This was used to select the searchBox input field on the CRM Web part

 Using JavaScript to connect CRM and SharePoint

I then use “Variable.Value” to assign the value of the Search Box when the window loads. This value is set to the site name and therefore will only show activities related to that given project

 Using JavaScript to connect CRM and SharePoint

This method was used as there was no connection between SharePoint and CRM apart from the project names.  Using JavaScript means we could make that connection.