Advertisement

08.06.2008 at 09:06AM PDT, ID: 23626239
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

Cannot print conntents of IFrame in CRM 4.0

Asked by MindenMan in Microsoft Dynamics

Hi all;
I'm using MSCRM4.0 and I've created an Iframe that refers to another html page that then brings up a map of where our customer is - as per the following article:
http://blogs.msdn.com/crm/archive/2007/08/01/adding-live-maps-to-microsoft-crm-3-0.aspx

The iFrame and map works a treat and brings up more or less any address in the UK.  However, when I go to the "print" button on the account window and the preview is generated I just get an empty window along with all the other account info printed.  I've tried just adding a print button with script to the html page.  This works kinda, in that the map prints but I also get numerous script errors such as:
 
Line 38 Char 1 LOCID_UI_DIR undefined

Line 174 Char 1 Object expected

Line 115 1 _bPresenceEnabled is undefined

These errors appear to come from the following page:
sfa/accts/edit.aspx?id={GUID of account is here}

My current print "fix" is using a print.js file as follows:
if ( printIsNativeSupport() )
  window.print2 = window.print;
window.print = printFrame;

// main stuff
function printFrame(frame, onfinish) {
  if ( !frame ) frame = window;

  function execOnFinish() {
    switch ( typeof(onfinish) ) {
      case "string": execScript(onfinish); break;
      case "function": onfinish();
    }
    if ( focused && !focused.disabled ) focused.focus();
  }

  if ( frame.document.readyState !== "complete" &&
       !confirm("The document to print is not downloaded yet! Continue with printing?") )
  {
    execOnFinish();
    return;
  }

 if ( window.print2 ) { // IE5
    var focused = document.activeElement;
    frame.focus();
    if ( frame.print2 ) frame.print2();
    else frame.print();
    execOnFinish();
    return;
  }
 
  var eventScope = printGetEventScope(frame);
  var focused = document.activeElement;
 
  window.printHelper = function() {
    execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
    printFireEvent(frame, eventScope, "onafterprint");
    printWB.outerHTML = "";
    execOnFinish();
    window.printHelper = null;
  }
 
  document.body.insertAdjacentHTML("beforeEnd",
    "<object id=\"printWB\" width=0 height=0 \
    classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">");
 
  printFireEvent(frame, eventScope, "onbeforeprint");
  frame.focus();
  window.printHelper = printHelper;
  setTimeout("window.printHelper()", 0);
}


// helpers
function printIsNativeSupport() {
  var agent = window.navigator.userAgent;
  var i = agent.indexOf("MSIE ")+5;
  return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFireEvent(frame, obj, name) {
  var handler = obj[name];
  switch ( typeof(handler) ) {
    case "string": frame.execScript(handler); break;
    case "function": handler();
  }
}

function printGetEventScope(frame) {
  var frameset = frame.document.all.tags("FRAMESET");
  if ( frameset.length ) return frameset[0];
  return frame.document.body;
}

And my HTML page is this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>

    <head>

    <title></title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <script type="text/jscript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" mce_src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script>
   
      <script type="jscript" src="print.js"></script>
<script type="text/jscript">
function window.onload() {
  idPrint.disabled = false;
}

var originalTitle;
function beforeprint() {
  idPrint.disabled = true;
  originalTitle = document.title;
  document.title = originalTitle + " - by Baseline Consultancy";
}

function afterprint() {
  document.title = originalTitle;
  idPrint.disabled = false;
}

</script>

<script type="text/jscript">

    var map = null;
    var Address = "";
    var latitude = null;
    var longitude = null;
    function GetMap()

    {
    // Try to get lat&long from the CRM

    latitude = parent.document.forms[0].all.address1_latitude.DataValue;

    longitude = parent.document.forms[0].all.address1_longitude.DataValue;
   
    //Get adress from CRM
    var addressline1 = parent.document.forms[0].all.address1_line1.DataValue;
    var city = parent.document.forms[0].all.address1_city.DataValue;
    var County = parent.document.forms[0].all.address1_stateorprovince.DataValue;
    var PostCode = parent.document.forms[0].all.address1_postalcode.DataValue;
    var Country = parent.document.forms[0].all.address1_country.DataValue;
   
if (Country == null)
    {
     Country = "United Kingdom"
     }

if (PostCode == null)
    {
     alert ("You must have a value for the Postcode in order to map the address, better still ensure you have the correct full address for a more accurate mapping!");
     }

      Address = addressline1+", "+city+", "+County+", "+PostCode+","+Country;

    map = new VEMap('myMap');

    map.LoadMap();
    if (latitude != null && longitude != null)

        {

        PlacePushPin(latitude,longitude);

        }

        else

        {

        map.Find(null,Address,null,null,0,10,true,true,true,true,FindCallBack);

        }

        }

        function FindCallBack(shapeLayer, results, positions, moreResults, e)

        {

        if(positions != null && positions.length > 0)

        {

        PlacePushPin(positions[0].LatLong.Latitude,positions[0].LatLong.Longitude);

        latitude = positions[0].LatLong.Latitude;

        longitude = positions[0].LatLong.Longitude;

        parent.document.forms[0].all.address1_latitude.DataValue = latitude;

        parent.document.forms[0].all.address1_longitude.DataValue = longitude;
       
      
      

        }

        }

        function PlacePushPin(lat, lon)

        {

        latlong = new VELatLong(lat,lon);

        customerPushPin = new VEShape(VEShapeType.Pushpin,latlong);

        map.AddShape(customerPushPin);

        map.SetCenterAndZoom(latlong,15);

        }

    </script>
     


    </head>

    <body onload="GetMap();">
<onbeforeprint="beforeprint()"onafterprint="afterprint()"  bgcolor="infobackground">
<p><input name="idPrint" type="button" value="Print this page" onclick="print()"/> </p>


    <div id='myMap' style="position:relative; width:600px; height:600px;"></div>

    </body>

    </html>

Any help would be greatly appreciated as this is driving me crazy!
Thanks
MM


Start Free Trial
[+][-]08.22.2008 at 06:13AM PDT, ID: 22289498

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Dynamics
Sign Up Now!
Solution Provided By: MindenMan
Participating Experts: 0
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628