Friday, June 14, 2013

CRM 2011 - Load a web page in an iframe using a URL thats in the record for the Entity.

I have an entity that has a URL as one of the fields. The Url points to a PDF document on the web. I want to display that PDF when the form opens, as part of the form. Something like this:

So the DocumentLocationfield points to a pdf. I want the PDF to be displayed, as shown below, when the update form is opened. Here's how:

1. Create a web resource for the solution, as follows:

<html><head>
    <title>HTML Web Resource</title>
  <meta charset="utf-8">
  </head><body>
    <script type="text/javascript">
     var objectExists=parent.window.Xrm.Page.getAttribute('fcbt_documentlocation');
     if(objectExists != null)
     {
           var fileName = parent.window.Xrm.Page.getAttribute('fcbt_documentlocation').getValue();
           document.write("Loading pdf from " + fileName);
           document.location.href=fileName;
     }
    </script>  
</body></html>

2. Associate that script with the OnLoad event of the form.

Thats it - now if you have a field called fcbt_documentlocation and it contains a valid url to a PDF, the form will open with the pdf displayed.

Note that the checking for null is essential - because it will always be null when inserting a row! 

No comments:

Post a Comment