Displaying an SharePoint document library as a subgrid or iframe in CRM 2011

Hi all,

Today I got a requirement of integrating CRM 2011 with SharePoint 2013 & show the SharePoint documents in a subgrid.

I know there are lots of blogs showing the integration technique which helps us to integrate SharePoint with CRM 2011. But after integration, I faced lot of challenges to run the view the document library under CRM. And above to that I struggled to show the SharePoint document library in a subgrid instead of navigation link.

Somehow I managed to succeed in my struggle & same I am sharing with you all guys.

As you might know we can’t insert SharePoint document library inside a subgrid on crm form because of its relationship behavior. So as a workaround we can insert an Iframe and dynamically we can set the url of the IFrame.

So to display the documents in IFrame we have to do some IE settings just to avoid the below error:“This content cannot be displayed in a frame”.

1. Navigate to Internet Explorer Tools–> Security tab

2. Select trusted sites and click sites button (highlighted)

3. Add your CRM site as well as your SharePoint site to the trusted zone

4. After  setting up the your trusted sites, select custom level from the same tab

5. Look for “Display mixed content” & Set this option to “Enable”.

Now your half work is done. Next task is to display the SharePoint documents under IFrame.

Note: Before starting make sure you have successfully integrated SharePoint with CRM 2011. To verify open any Account record and see if you can add documents under the document navigation link.

Now let’s start with the customization of Account entity for displaying SharePoint document under IFrame.

6. Navigate to Settings–>Customizations–>Customize the system

7. Under Components, click on Entity and then navigate to Account Entity–> Forms

8. Open the preferred form like Information & Insert a One Column section in an existing Tab or Insert new

9. Insert a IFrame under  the section and set the properties as per the below screen

10. Click on the Form properties

11. Create a web resource

12. Click on Text Editor and add the javascript code

For CRM 2011:

function onLoad()

{

var navDocument;

navDocument = document.all.navDocument;

if (navDocument != null)

{

Mscrm.DocumentLocationHelper.loadLocationsArea(navDocument , true);

//navDocument.style.display = “none”;

var recordId=Xrm.Page.data.entity.getId().replace(“{“,””).replace(“}”,””);

var  oTypeCode= Xrm.Page.context.getQueryStringParameters().etc;

document.all.IFRAME_Documents.src=”/tools/documentmanagement/areas.aspx?oId=%7b” + recordId + “%7d&oType=”+oTypeCode+”&pagemode=iframe”;

}

}

For CRM 2013:

// JScript source code
function onLoad() {
var navDocument;
navDocument = document.all.navDocument;
if (navDocument != null) {
Mscrm.DocumentLocationHelper.loadLocationsArea(navDocument, true);
//navDocument.style.display = “none”;

var recordId = Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”);
var oTypeCode = Xrm.Page.context.getQueryStringParameters().etc;

var CurrentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId().replace(“{“,””).replace(“}”, “”);
document.all.IFRAME_Documents.src = “/tools/documentmanagement/areas.aspx?formid=%7b” + CurrentFormId + “%7d&oId=%7b” + recordId + “%7d&oType=” + oTypeCode + “&pagemode=iframe&rof=true”;

}

}

For CRM 2015:

function onLoad() {
var recordId = Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”);//Entity record id
var oTypeCode = Xrm.Page.context.getQueryStringParameters().etc;//Entity Type code. for lead it is 4
var IFrame = “IFRAME_Documents”;//Iframe Name
var relName = Xrm.Page.data.entity.getEntityName() + “_SharepointDocument”; //Entity Relation name. Like for Lead it is Lead_SharepointDocument
SetIframeContent(IFrame, oTypeCode, relName, recordId);
}
function SetIframeContent(iframeObjId, objectType, areaName, recordId) {
var iframeObject = Xrm.Page.getControl(iframeObjId);//Get iFrame control
if (iframeObject != null) {
//Set iframe URL
iframeObject.setSrc(“/userdefined/areas.aspx?oId=” + recordId + “&oType=” + objectType + “&pagemode=iframe&security=852023&tabSet=” + areaName + “&rof=true&inlineEdit=1”);
}
}

13. Save & Close the editor.

14. Add the function under the form properties, inside the Event handler properties.

15. Click Ok. Then publish the customization to finish the customization.

16. Now open the same account record & see if you can see the document library inside the IFrame.

17. You will see Iframe like:

So in this way we can integrate sharepoint with CRM online.

Namaste 🙂

Megh

Advertisements

74 thoughts on “Displaying an SharePoint document library as a subgrid or iframe in CRM 2011

  1. Microsoft Dynamics CRM with Microsoft SharePoint integration introduction | Roman's Blog

  2. Hello,

    Thank you for this post. However, when it displays the document location it says that there are no sharepoint locations associted with it although when I go to the Documents link on the side navigation it shows the document locations.

    Since we are using managed metadata, when we do view the sharepoint location using the side navigation, it shows the document location as it would in IE and not in the grid layout. Would this cause the iframe not to show up properly?

    Thanks for any assistance.

    • I believe I’m having a similar issue as Matthew. The form displays an error message “This record does not have a SharePoint location associated with it. Add a SharePoint Location.”

      However when I click the Documents link in the navigation pane the folders appear.

      Thank you

      • Hi Ryan/Mathew,

        Yes, you both are right. Initially I thought its a default behaviour but after checking I found that we have to do some modification in the url like we can try passing formid as a parameter along with recordid.
        Ex. “tools/documentmanagement/areas.aspx?formid=%7xx053a39a-041a-4356-acef-ddf00182762x%7d&oId=%7bF0A2D5A4-BADF-E211-97E2-D8D3855B1531%7d&oType=1&pagemode=iframe”

        Currently I can’t debugg issue due to unavailability of CRM system at my side. Once I’ll connect to CRM system, I will try to resolve the issue.
        Happy coding.

        Thanks
        Megh

      • Hi Ryan/Mathew,

        If the below issue still exists with you then try to remove the Iframe and add it again.
        And see if the issue still exists.

        Thanks
        Megh

  3. Any luck on resolving the parameters? Also, there is another issue, when we disable cross-browsing to enable the iframe, the ribbon stays in “Document Mode” and you cannot access the other buttons

    • Hi Ryan,

      Still not. I am currently not working on it due to some other prioeities.

      So it wud be bette if you can put some effort to find the solution.

    • Hi Ryan,

      Please see my latest comment to Mick, there I have given a workaround.

      For your refrence..

      Change the onLoad function with this function (onLoadNew):

      function onLoadNew()
      {
      var navDocument;
      navDocument = document.all.navDocument;
      if (navDocument != null)
      {
      var recordId=Xrm.Page.data.entity.getId().replace(“{“,””).replace(“}”,””);

      //tab_4 is theTab name of the Tab where the Iframe is located
      var sTab = Xrm.Page.ui.tabs.get(“tab_4″);
      sTab.setDisplayState(“collapsed”);
      document.all.IFRAME_Documents.src=”/tools/documentmanagement/areas.aspx?oId=%7b” + recordId + “%7d&oType=1&pagemode=iframe”;
      }
      }

      Here I have added 2 more lines to collapse the tab where you Iframe (inside the section)
      And then add the below function on IFRAME OnReadyStateComplete event. This function will again expand the tab once the iframe is completed.
      function RefreshRibbon()
      {
      var iFrame = document.getElementById(“IFRAME_Documents”);
      if (iFrame.readyState != “complete”) {return;}

      var elTab = Xrm.Page.ui.tabs.get(“tab_4″);
      elTab.setDisplayState(“expanded”)
      }

      Thanks
      Megh

  4. Hi Megh,

    I’ve tried using your solution in a CRM UR 12 environment and I’m running into a problem with the control ribbon. When I set the iframe src, the control ribbon opens to the documents area, but it won’t change back when I click on another part of the form, so the save, assign, etc buttons on the main section of the ribbon become unavailable. Opening a sub-navigation link (such as closed activities) and returning to the main form refreshes the ribbon context, but then I can’t get the document ribbon to reload when I click in the iframe area. Any suggestions?

    • Hi Mick,

      Yes you are right. I investigated on the issue that you have demonstrated in your comment and found that this is with the context senstivity of the Ribbon. If you look closely, the Iframe for sharepoint document holds the focus of the form and will not loose it until you click on the navigation links.

      So I tried lot of things and came up with some work around. Just see if it helps you to resolve the issue.
      Change the onLoad function with this function (onLoadNew):

      function onLoadNew()
      {
      var navDocument;
      navDocument = document.all.navDocument;
      if (navDocument != null)
      {
      var recordId=Xrm.Page.data.entity.getId().replace(“{“,””).replace(“}”,””);

      //tab_4 is theTab name of the Tab where the Iframe is located
      var sTab = Xrm.Page.ui.tabs.get(“tab_4”);
      sTab.setDisplayState(“collapsed”);

      document.all.IFRAME_Documents.src=”/tools/documentmanagement/areas.aspx?oId=%7b” + recordId + “%7d&oType=1&pagemode=iframe”;
      }
      }

      Here I have added 2 more lines to collapse the tab where you Iframe (inside the section)
      And then add the below function on IFRAME OnReadyStateComplete event. This function will again expand the tab once the iframe is completed.
      function RefreshRibbon()
      {
      var iFrame = document.getElementById(“IFRAME_Documents”);
      if (iFrame.readyState != “complete”) {return;}

      var elTab = Xrm.Page.ui.tabs.get(“tab_4”);
      elTab.setDisplayState(“expanded”)
      }

      Try this and let me know if this solution works for you. 🙂

      Cheers!!!
      Megh

  5. HI,

    I have similar problem like Matthew / Ryan. Document location in IFrame report there is no document location but there is. I can’t find any solution for this problem and I had no luck with geting formId from original document location Frame in left side and passing it into IFrame url. Anyone solved this problem ?

      • Hi,

        SharePoint configuration is OK. When I click on left side “documents” so I regulary see created DocumentLocation including testing document in it. But IFrame on form does not reflect this location. And i find up, taht formId I mentioned before is static for every record so I get it from browser and set into IFrame URL so it looks:

        var link2 = “/tools/documentmanagement/areas.aspx?formid=12e0f22f-0108-4aab-823a-937591ac6c0c&oId=%7b” + recordId + “%7d&oType=1&pagemode=iframe”;
        document.all.IFRAME_Documents1.src=link2;

        but nothing change. This is only web I find, that solving this specific problem and I starting be desperate. Cannot be some difference that I using base and set language Czech ?

      • Edit: I reset connection to SharePoint and recreated webs and sites (Sites creating automatically), but nothing changed.

      • Edit2: I have progress. IFrame is still empty, but dont crashing when i click to “Add new location…” from it. It was because IFrame tried looking for locations from other CRM organisation. I dont know why when I dont specified organisation nowhere, but now I upgraded IFrame URL to

        var link2 = “http://myserver/myorganisation/tools/documentmanagement …

        but still it dont pairing with record location automatically. I must click to add new location in IFrame, choose new folder … after that it writes, that this location exist and will be paired and after that it works, but this procedure is strange and complicated

  6. Hi Tomas,

    try to add below line your code..and see if it works.

    Mscrm.DocumentLocationHelper.loadLocationsArea(navDocument , true);

    Thanks
    Megh

  7. Hi,

    unfortunately it does not help 😦 and I see if I manualy add DocumentLocation(merge with physical location of record) into IFRame doc.loc and I save and close record and after that I open it again so in IFrame is no document location again. It happened before you last suggestion too.

    • Hi Gaur, i’m trying to display an SharePoint document library as a subgrid or iframe in CRM 2013.

      I did all those steps but i think that i have the same problem has “Tomas Linhart” , there is no error onLoad and I’m using a different language… “pt”

      Can you help?

      • What error you are getting. And make sure you are using the right entitytypecode.
        Becuase Tomas was also having the same issue. He was using the wrong entitytypecode and i hope you have used the below code.

        Note: Don’t forget to replace “ & ” from you keypad.

        var oTypeCode = Xrm.Page.context.getQueryStringParameters().etc;

        var CurrentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId().replace(“{“,””).replace(“}”, “”);
        document.all.IFRAME_Documents.src = “/tools/documentmanagement/areas.aspx?formid=%7b” + CurrentFormId + “%7d&oId=%7b” + recordId + “%7d&oType=” + oTypeCode + “&pagemode=iframe&rof=true”;

      • I will use this IFRAME on a Custom entity and Note that custom entity object type codes may change during import and are not guaranteed to be the same between systems… :S

        and my entitytypecode (ObjectTypeCode) = 10005

        but I still dont understand where I will change the entitytypecode …

      • Here there is a oTypeCode which need to be set dynamically.
        like this
        var oTypeCode = Xrm.Page.context.getQueryStringParameters().etc;
        document.all.IFRAME_Documents.src = “/tools/documentmanagement/areas.aspx?formid=%7b” + CurrentFormId + “%7d&oId=%7b” + recordId + “%7d&oType=” + oTypeCode + “&pagemode=iframe&rof=true”;

        And also don’t forget to debugg the javascript if yo u still face the issue.

      • hey Megh,

        it shows no error. but when i open a record, Instead of loading in the IFRAME(like want it), onload it opens the Documents Ribbon option.

      • Hey Carlos,

        I got your problem. It seems to be a focus issue. Try to do one thing.
        I don’t have solution right now for that but yes have 1 workaround.

        Put that iframe in a separate tab and set the focus on to some different tab.
        And if that also doesn’t work then collapse the tab onload + set the focus onto some different tab.

        Hope this time it work for you.
        Megh

      • Hi its working except the focus part.
        I use
        var CurrentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId().replace(” {“,””).replace(“}”, “”);

        var sTab = Xrm.Page.ui.tabs.get(“tab_Documentos”);
        sTab.setDisplayState(“collapsed”);

        //FOCUS PART
        var tabObj = Xrm.Page.ui.tabs.get(“tab_Geral”);
        tabObj.setFocus();

        //ALSO tried this way
        //Xrm.Page.ui.tabs.get(“tab_Geral”).setFocus();

        document.all.IFRAME_Documents.src = ……

        //ALSO tried this way
        //Xrm.Page.ui.tabs.get(“tab_Geral”).setFocus();

        and

        function RefreshRibbon()
        {
        var iFrame = document.getElementById(“IFRAME_Documents”);
        if (iFrame.readyState != “complete”) {return;}

        var elTab = Xrm.Page.ui.tabs.get(“tab_4”);
        elTab.setDisplayState(“expanded”)
        }

        like you said ii

        Can you help me with this focus part??

      • Hi Carlos,

        Give me sometime. I will look into it and get back to you asap.

        Thanks
        Megh

      • hey MeghShyam Gaur say something …
        I wanna to know how to do it on CRM 2013 too.
        thanks 🙂

      • Hi Alex,

        Just add this below line
        var CurrentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId().replace(“{“,””).replace(“}”, “”);

        change the below line from
        document.all.IFRAME_Documents.src=”/tools/documentmanagement/areas.aspx?oId=%7b” + recordId + “%7d&oType=”+oTypeCode+”&pagemode=iframe”;
        to
        document.all.IFRAME_Documents.src = “/tools/documentmanagement/areas.aspx?formid=%7b” + CurrentFormId + “%7d&oId=%7b” + recordId + “%7d&oType=” + oTypeCode + “&pagemode=iframe&rof=true”;

    • hey AlexandrDark when you get an answer from MeghShyam Gaur say something …
      I wanna to know how to do it on CRM 2013 too.
      thanks 🙂

    • Hi Alexander,

      Please change the javascript for CRM 2013 version
      // CRM 2013 source code
      function onLoad() {
      var navDocument;
      navDocument = document.all.navDocument;
      if (navDocument != null) {
      Mscrm.DocumentLocationHelper.loadLocationsArea(navDocument, true);
      //navDocument.style.display = “none”;
      var recordId = Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”);
      var oTypeCode = Xrm.Page.context.getQueryStringParameters().etc;
      var CurrentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId().replace(“{“,””).replace(“}”, “”);
      document.all.IFRAME_Documents.src = “/tools/documentmanagement/areas.aspx?formid=%7b” + CurrentFormId + “%7d&oId=%7b” + recordId + “%7d&oType=” + oTypeCode + “&pagemode=iframe&rof=true”;

      //document.all.IFRAME_Documents.src=”/tools/documentmanagement/areas.aspx?oId=%7b” + recordId + “%7d&oType=”+oTypeCode+”&pagemode=iframe”;

      }

      }

  8. MeghShyam,

    When I tried your suggestion above, I get the following error:

    There was an error with this field’s customized event.
    Field:window
    Event:onload
    Error:undefined

    Can you help me with this?

    • Hi Abu,

      Try to replace the double quotes (“) in the js by typing from your keyboard.

      This happens when we copy the code from some blogs but double quote are not the original one which we have from our key pad.?

      Or can be a bracket missing in your javascript.

      Hope you got the idea.

      Cheers!!!
      Megh

      • Thank you Megh. I go t it to work.

        Two other issues:

        1. The default view is the Documents for the gridview. I would have to click the tabs for the form in order to view the grid in the IFrame. How would I change it to display the form on load instead of the Documents?

        2. The grid is displayed properly in the IFrame if I’m logged in as admin. If I log in as a general CRM user, the sub grid is no longer displayed and displays the SharePoint page. Any suggestions? Is it a user permissions thing?

  9. Hi Aby,

    for the 1st issue..I think it is the focus issue. its better to create a separate tab and move the iframe to it. And on form load you can collapse the Sharepoint tab and set the focus to some other tab of field using javascript.

    For 2nd issue, yes, please check if the user have access to sharepoint site + check the security role too for that user.

    Thanks
    Megh

    • Hi Gaur, do you know how to create folders in sharepoint from the CRM?

      I want to create 6 folders in sharepoint automatically after creating a record in CRM…

      I would appreciate the help… Thanks 😀

      • Hey Carlos,

        Yes, there is a way to create folders in sharepoint using plugin but only from on-premise CRM because in online we can’t put supporting sharepoint dll’s.

        Or if you are using CRM online then the only way is to create a console application/Web app by consuming crm webservice + sharepoint dll’s.

        Thanks
        Megh

      • Well on-premises is out of question, so using WebService and sharepoint dll’s…. any idea where to start??? or do you have any sample code ?? thanks

      • ok. I will share the details in my upcoming post. So give me some time.
        But just to give you an overview, we can add sharepoint assemblies to access the sharepoint directory in our plugin code which will get trigger on creation of crm record.

        But for that, you have to register the sharepoint dll’s on the crm server so that CRM platform layer will able to talk to sharepoint dll’s.

        Thanks
        Megh

  10. Hi MeghShyam, have you enable server based sharepoint integration on dynamics crm online spring 14 ??

    because i think that this solution with server based sharepoint integration wont work…

    • Hello, I have the same question as carloafc.

      Can you confirm if this will work with Spring Update 14 and the new SharePoint integration? I am getting the undefined error as well. I have double checked the code and replaced all ” (double quotes).

      There was an error with this field’s customized event.
      Field:window
      Event:onload
      Error:undefined

      • I haven’t checked this with spring 14′ updates. So please give me sometime and will let you know the solution.

  11. dynamics crm 2013 sharepoint document location in subgrid - Tech Forum Network

    • Not yet. Need to dig the html code deeply to get it resolved. Please let me know if you have any input from your troubleshooting.

  12. i am also getting this error. As soon as i open the form, the focus goes to Documents navigation. Can you please help and give code. I am working on CRM 2013SP1

  13. I know this thread has been dead for w while, So i am praying that you are still looking at this stuff. I followed all the instruction( including in the comments), and it works kind of. It Starts to load in the Section but then takes over the whole page as if i had gone to the documents library through the Documents button.Is there a way to make it now take over the whole screen.
    I am using SP 2013 RU1 On Premise.

    • Hi Nick, I am trying hard to fix all the reported issues. Will share if have anything solid for you guys.

      Thanks
      Megh

    • Hi Gaurav, I’ve haven’t tried this with CRM 2015 yet but I will try soon.

      Will get back to as soon as I’ve js for 2015 and if you come up with same then do share with us.

  14. Hi Gaur,

    I tried the javascript you have given on a CRM 2013 on-premise server but could not get that to work. The error I’m getting is “Unable to set property ‘src’ of undefined or null reference”.
    Below statement causes this error.
    document.all.IFRAME_Documents.src = “/tools/documentmanagement/areas.aspx?formid=%7b” + CurrentFormId + “%7d&oId=%7b” + recordId + “%7d&oType=” + oTypeCode + “&pagemode=iframe&rof=true”;

    If I comment out the above statement it doesn’t give any error but when I go to a record (contact), it directly opens up the document grid instead of showing that grid in an iframe. It is very much appreciated if you could help me on this.

    Thank you.

    • Hello, I guess you are not using the correct name of the iFrame. In my case it was “IFRAME_Documents“. so do verify it once and see if you are able to fix it.

      If that doesnt solve your issue then it might be the latest rollup issue.

      Thanks
      Megh

  15. Sorry, I found the iFrame name. Now I’m not getting that error but still it directly opens up the document grid instead of showing that grid inside the iframe. Could you please help me with fixing this? I have given the SharePoint site url as the iFrame url. Is that correct? Thanks a lot for your support on this.

  16. Hi Megh,
    Thanks so much for trying to help. It was a focus issue and I was able to fix that problem by adding the code you have suggested in one of the comments. I should have read all the comments thoroughly before asking you, sorry about that. It really helped and thanks again for sharing this solution and your support. really appreciate that.

  17. Hi Megh,
    I have followed your code and tried on CRM2015 Online environment under Account entity. The js only gets as far as ‘if (navDocument != null)’ and exited out. It seems that ‘navDocument’ is undefined before it can reach to any other code. Any idea what’s causing it? I could see documents from the out of box panel on Account Form…

    • Hi Andy, Great to hear that someone is looking after this activity. Do not forget to share your findings.

      Actually this was implemented way back in CRM 2011 version but since I’ve left that company I didn’t get a chance to try with new versions.
      However I did some R&D for CRM 2013 after getting lot of responses on this post but its been quite some time I didn’t touched this activity.

      Thanks
      Megh

  18. Doring research for an alternative solution. Can this be implemented into a simple browse / use a file share (UNC share) instead, like using the standard Windows file Explorer on a local drive ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s