SharePoint 2010 and CRM 4 - Dynamic Documents

 

Technorati Tags: sharepoint crm integration,sharepoint,crm sharepoint,IFRAME

Hi SharePoint Folks,

Before I say anything – This is for those who have CRM 4 and SharePoint 2010 in there environments. I am sure there are many posts (by others ) on doing the same thing in CRM 2011 (actually its built in the product).

So here we go – Do you have lot for records in CRM ? Plus you want an easier Document management other then( attach file link). Or second best – you already have a IFRAME in CRM form which shows the SharePoint document library ? Ok My idea is built on this second approach and it helps you to filter only relevant document shown in the list at Runtime or Dynamically.

Here is what this I intent to solve - Imagine I have a CRM Account who has 10 associated document, imagine you have 200 CRM accounts, this gives us 200 X 10 = 2000 documents. Each time the account form is opened, the CRM user sees 2000 files, BUT which ones are relevant to this account? get the problem !

Typical CRM showing ALL the documents from SharePoint BUT not showing the relevant once

image

We will solve this by asking SharePoint to give CRM only Relevant documents (we will enhance this too, look at the bottom of this blog)

What you need

1. A SharePoint site document library. (In order to use this solution, we need to associate the CRM entity with accounts, i.e.. have a column in SharePoint and enter the CRM entity name in it, I’m using Account name. I have done it already for the blog post.)

2. A CRM deployment

3. This Post :)

Edit the CRM4 Forms

In CRM

1. Add an IFRAME to in the CRM Form, for this example we have chosen Account Form. Shown below

2. Add the name and add the SharePoint site URL here. (SharePoint site url, or the url of document library, it does not matter what you put here).

3. ENSURE that we check mark the Option Pass record object-type code and unique identifier as parameters. (we do this because we Want CRM to pass parameter information to SharePoint).

4. Click OK to confirm.

image

In SharePoint

1. Open the SharePoint site URL and navigate to the Document library where the CRM documents are stored.

2. Add a column and give it a name CRMID and in the type select single line of text. Why are we doing this ? – For this solution to work SharePoint needs to know which document belong to which CRM account, we do this by creating a Text column and filling it with Exact name of CRM account. Alternatively we can make a BCS connector which basically pulls the accounts name from CRM and we can go for “ External data“ type column.

image

Now next time we add file in SharePoint and fill need to fill the Account name like this, Even when we upload from CRM we will get similar screen to fill the Account data.

image

 

3. Now Click on Create View and type a name CRMView Figure 4, and select “standard View”- Figure 5. And Ensure that you select the CRMID column name

image

image

image

image

4. Now Click ok at the bottom and you should see the new View similar to below image

image

5. Now Click on the column CRMID and select any of the CRMID, below figure

 

image

after you select an filter copy the URL, paste it in a notepad, see below figure.

image

And At the end of the URL remove TestUser1 you will get something like the below image

image

 

Back to CRM

1. Now Go to Account Edit mode and Click Form Properties. Below figure

image

2. The Form properties opens Select OnLoad and Click Edit.

 

image

3. Now in the Code Region type the below code. And enter the SharePoint URL, that we got in the notepad, in the highlighted region, figure below, Also ensure that Even is enabled is checked

image

Here is the script:

    1: var CRM_FORM_TYPE_CREATE = 1;
    2: var CRM_FORM_TYPE_UPDATE = 2;
    3: var SharePointURL= "";
    4: if(IsOnline())
    5: {
    6:    switch (crmForm.FormType)
    7:    {
    8:       case CRM_FORM_TYPE_CREATE:
    9:       case CRM_FORM_TYPE_UPDATE:
   10:        SharePointURL= "<sharepointURL>”;
   11:  SharePointURL+= encodeURIComponent(crmForm.all.name.DataValue);
   12:                   break;
   13:   }}

4. Click ok here and exit out of this windows and click on save and close > save and close till you reach the main CRM UI, Publish your changes

 

The Result

1. I open the Account in CRM

image

And I open the account Testuser1 and navigate to the IFRAME

image

 

And Yes I only see the Documents relevant/ applicable to my open account.

Enhance this ?

Now folks wouldn’t it be cool If my CRM user can see all the information my SharePoint has for that CRM account ? Meaning not only the documents stuff but any information on SharePoint, internet, SAP, public folder, file shares etc., basically whatever SharePoint can search

1. Add one more IFRAME to the CRM form and tweak the script, just add one more line which calls the search center from SharePoint and pass the account name as parameter

High level steps

1.  Add the IFRAME – Give it a name e.g.: IFRAME_SEARCH.

2. Add the below line and that does the trick

IFRAME_SEARCH = “https://sharepointsiteurl/searchcenter/pages/Results.aspx?k=”;  see below description, this will change according to your SharePoint farm.

/* usually the search url would like the one above. To get the correct url, go to your SharePoint site do a search for “TESTSEARCH”, Look at the url it will   look similar to https://sp2010/searchcenter/pages/Results.aspx?k=TESTSEARCH, remove the trailing TESTSEARCH, and that becomes the URL string :).*/

 IFRAME_SEARCH+= encodeURIComponent(crmForm.all.name.DataValue);

That’s it, We are ready to go !

Thanks for reading and I will be back !