Microsoft Dynamics CRM 2011

Microsoft Dynamics CRM 2011

Tuesday, October 8, 2013

Step-By-Step How to open a local File from a CRM Form

by Carmel Schvartzman

In this walkthrough we will learn how to open a local File from a CRM Form in Dynamics CRM 2011. We'll create a link button on the Main CRM form of the Article entity, to open a file from the local File System.

Although CRM 2011 allows us to add a link to some URL, it won't work for a link to a local file .
So if we need to open a local PDF, DOCX or PNG local file, the way to do that is to turn a string file address into an hyperlink, using a Web Resource written in javascript.

A Web Resource is a virtual html, jscript, css, picture or Silverligth file stored in the CRM database, and identified by a unique URL. After creation, a Web Resource can be used in many CRM Forms, enhancing its functionality and/or appeareance.

Our link button will open a pdf file on our Form: the following snapshop shows how the final form will appear:




  1. To create the link, let's make a new Web Resource:

     
  2. Give the Resource an appropriate name, and write the " _ " before of the display name , making it easier to find our resource between hundreds of files:



    The "Type" of the resource must be "Script". Open the Text Editor, and write the javascript function:


    3. The function will get an "fldName" parameter containing the name of the string field to convert to a link:


    Using the CRM notation, get the string inside the field: Xrm.Page.getAttribute("...").getValue().
  3. After checking whether the string containing the file path is not null, create an anchor html tag ( <a> ) that will hold our path, opening it in a new window ("target=_blank"):
  4. Next, get the control containing the field:



    ...and set our <a> tag as the innerHTML of the control, hiding the original text box control:
  5. Save the Script and Publish the Web Resource. Next, go back to the Article Main form, where we want to add our File attachment link:


    On the Article's form, add a New string Field:


    Select from the list only the custom fields, and drag and drop the new field to the CRM Form:





    Now the field is on the form, but because it will hold a file address, let's expand it to two columns:
  6. Our next task is to add the Web Resource script to our form. Go to "Form Properties":
  7. We need to add the script as a javascript library. On the Properties dialog, go to the Libraries in the Event List:
  8. Inside the Look up Record list, we'll find our script on the top, just because we add the " _ " at the head of the Display name of the Web Resource:
  9. After we added the library, we must select which Event Handler will call the function: Select OnLoad and click "ADD":
  10. Select the library we just added:
  11. Next, type the function name we coded on the script, and the LOGIC NAME of the CRM field holding the file path (remember that the LOGIC CRM name is the same as the SCHEMA NAME but in small caps):

    That's all concerning to the Web Resource.
  12. Now let's see how it works. Create a new article. Fill up the required fields and type the address of the file:

    As you can see, you can input the address in a text box. Save the Article and close the CRM form.
  13. Now open the Article we just created, and you'll see that the address string has been converted to a link to the file:
  14. Click the link and the PDF file will open:


    That's all...Enjoy Dynamics CRM


    כתב: כרמל שוורצמן

7 comments:

  1. I followed your instructions on my configuration to open c:\sample.pdf.
    Firstly the address string doesn't convert to a link to the file. The link actually appears below below the address string.
    Secondly, the link (c:\sample.pdf) doesn't work it doesn't open the pdf, nothing happens.
    Any ideas - I'm a bit deperate

    ReplyDelete
    Replies
    1. The Microsoft Dynamics Crm Club: Step-By-Step How To Open A Local File From A Crm Form >>>>> Download Now

      >>>>> Download Full

      The Microsoft Dynamics Crm Club: Step-By-Step How To Open A Local File From A Crm Form >>>>> Download LINK

      >>>>> Download Now

      The Microsoft Dynamics Crm Club: Step-By-Step How To Open A Local File From A Crm Form >>>>> Download Full

      >>>>> Download LINK DB

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This code contains DOM objects which is not supported by CRM. Right ?

    ReplyDelete
  5. The Microsoft Dynamics Crm Club: Step-By-Step How To Open A Local File From A Crm Form >>>>> Download Now

    >>>>> Download Full

    The Microsoft Dynamics Crm Club: Step-By-Step How To Open A Local File From A Crm Form >>>>> Download LINK

    >>>>> Download Now

    The Microsoft Dynamics Crm Club: Step-By-Step How To Open A Local File From A Crm Form >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete