Open local file/folders in Dynamics CRM 2013

For some reason, you might want to open a location using the file:// protocol in Dynamics CRM.

Result :

result2

In our case, we have 100K+ heavy scan files (>2MB/file) on a network share. Of course, I could publish them on an http server or on Sharepoint, but the engineering and sales department using these files need a very ergonomic and reliable access, and the IT department needs to be able to process all the files extremely quickly. Thus, a link that opens a folder directly on windows explorer best suits our needs (and all users are either in our LAN or connected via VPN). On top of that, we have to deal with access security, and our use case is not supported by default with the CRM/Sharepoint integration.

Of course, the first thing that comes to mind is to use the URL type for the field :

url-type2

But you will soon find out that there is a constraint on the protocols allowed…

url-validation2

Another solution is to embed an iFrame directly in the form. In our case, the results were very poor : we had refresh issues with the scroll, and no navigation (enter into a folder => no way to go back).

Ok, so let’s dive in, and make it work…

If you want to add a nice icon for the link, you can find one easily on : https://www.iconfinder.com/

In case you need to scale it, you can use The Gimp :

gimp-resize

Then, add it as a web resource :

webresource-img3

Now, create a new webresource : an html page with a small embedded javascript to update the dynamic URI.

html-webres3

Content of the webpage (you might want to do better than that, js in another webres, headers…) :

<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <a id="doclink" style="border: 0px currentColor;" href="http://www.example.com" target="_blank">
      <img style="border: 0px currentColor;" src="stsr_folders_icon.png">
    </a>
    <script language="javascript" type="text/javascript">
      var linkval = window.parent.Xrm.Page.data.entity.attributes.get("stsr_documents").getValue();
      var a = document.getElementById('doclink');
      a.href = "file:"+linkval;
    </script>  
  </body>
</html>

Using window.parent.Xrm.Page.data.entity.attributes.get(“stsr_documents”).getValue() enables you to access a value in a field. In my case, I used a field “stsr_documents” to store the full path to the documents, so that it remains easy to verify and quick to load (it would be possible to make asynchronous request to the webservice to build the path asynchronously from the js, but this is inefficient and error-prone).

The javascript replaces “http://www.example.com by the local file:// location, using the value found in the stsr_documents field. By the way, there should be a straightforward way to do it, js gods please comment 🙂

Insert this simple HTML page into the form :

html-webres-reg

Publish…

If you run into any cache problem, or if you need to debug your javascript, you may use F12 on internet explorer.

debug

Ok, that’s all : please comment if you have any improvement ideas. Thank you.

9 thoughts on “Open local file/folders in Dynamics CRM 2013”

  1. When I try to run through your tutorial I end up with a box that has the JS script in it. How do you like the icon to this? And how do you define exactly where the location is for the item?

    Thanks!

    1. Dear Meghan,

      Tank you for your comment, and sorry for the late reply : there was a lot of spam in the comments, I missed your post.

      You end up with a box containing the JS : when you edit the content of the web resource, make sure that you write the HTML in the “source” tab, not in the “rich text” tab.

      Source tab

      To add the icon, I used the “img” tag in the link : see the HTML code in the post.

      The location is in fact the uri you would write in explorer to find your file or folder. Example : \\my-server\my-share\my-file.docx

      Don’t hesitate if you need more information.

  2. Hi Raphael,
    Thanks for this great help, i still have probs though pointing to a local folder. Following your example, it add´s the Ip of the CRM Server destroying the link.

    Could you give another example?

    Is it possible to use more than one field in linkval?
    If so, could you make an example

    1. Dear Morty,

      Sorry for the late reply : did you find a solution in the meantime?
      If not : what is your CRM version, and could you share the code that creates the URL, as well as the resulting URL?

      Thank you, have a nice day.

  3. Hi Raphael,

    I have copied your instruction word for word, but it seems it will not redirect and is coming up with an error.
    SEC7134: Resource ‘file://********/Company/Account%20Managers’ not allowed to load.
    I’m a little bit lost and uncertain what to do.

    Many thanks
    Ollie

    1. Hi Ollie,

      A few ideas to find the cause of the issue :

      1. Could you just copy your file://xxx link in an explorer windows (the file browser, not IE), and check that you have access?
      If it works, we can exclude a firewall problem.

      2. If it is not a firewall issue, is it a browser issue? => Did you try with Internet Explorer? This method is not supported by Chrome without an external plugin.

      You may find this post useful : https://stackoverflow.com/questions/34901523/file-url-not-allowed-to-load-local-resource-in-the-internet-browser

      If this is an option for you, you could use WebDAV. A solution with WebDAV would be far more compliant with web standards.

      Have a nice day.

  4. Hi Raphael,

    Thanks for such a quick response;

    1, I can copy the location into the browser and it relocates to the file explorer normally.

    2, I use Edge as standard but I have tried Internet Explorer and Chrome to no avail.

    I’ve had a look through that link but I’m uncertain as to where I’m going wrong.

    Any advice would be appreciated.

    Many thanks
    Ollie

    1. Hi Ollie,

      Could you post a print-screen of the link that appears when you “hover” with the mouse cursor on top of the link created by the CRM page?

      Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *