MindenMan
asked on
Cannot print conntents of IFrame in CRM 4.0
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={GU ID 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.insertAdjace ntHTML("be foreEnd",
"<object id=\"printWB\" width=0 height=0 \
classid=\"clsid:8856F961-3 40A-11D0-A 96B-00C04F D705A2\">" );
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHe lper()", 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("F RAMESET");
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].a ll.address 1_latitude .DataValue ;
longitude = parent.document.forms[0].a ll.address 1_longitud e.DataValu e;
//Get adress from CRM
var addressline1 = parent.document.forms[0].a ll.address 1_line1.Da taValue;
var city = parent.document.forms[0].a ll.address 1_city.Dat aValue;
var County = parent.document.forms[0].a ll.address 1_stateorp rovince.Da taValue;
var PostCode = parent.document.forms[0].a ll.address 1_postalco de.DataVal ue;
var Country = parent.document.forms[0].a ll.address 1_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,long itude);
}
else
{
map.Find(null,Address,null ,null,0,10 ,true,true ,true,true ,FindCallB ack);
}
}
function FindCallBack(shapeLayer, results, positions, moreResults, e)
{
if(positions != null && positions.length > 0)
{
PlacePushPin(positions[0]. LatLong.La titude,pos itions[0]. LatLong.Lo ngitude);
latitude = positions[0].LatLong.Latit ude;
longitude = positions[0].LatLong.Longi tude;
parent.document.forms[0].a ll.address 1_latitude .DataValue = latitude;
parent.document.forms[0].a ll.address 1_longitud e.DataValu e = longitude;
}
}
function PlacePushPin(lat, lon)
{
latlong = new VELatLong(lat,lon);
customerPushPin = new VEShape(VEShapeType.Pushpi n,latlong) ;
map.AddShape(customerPushP in);
map.SetCenterAndZoom(latlo ng,15);
}
</script>
</head>
<body onload="GetMap();">
<onbeforeprint="beforeprin t()"onafte rprint="af terprint() " 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
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={GU
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.insertAdjace
"<object id=\"printWB\" width=0 height=0 \
classid=\"clsid:8856F961-3
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHe
}
// 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);
case "function": handler();
}
}
function printGetEventScope(frame) {
var frameset = frame.document.all.tags("F
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].a
longitude = parent.document.forms[0].a
//Get adress from CRM
var addressline1 = parent.document.forms[0].a
var city = parent.document.forms[0].a
var County = parent.document.forms[0].a
var PostCode = parent.document.forms[0].a
var Country = parent.document.forms[0].a
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,long
}
else
{
map.Find(null,Address,null
}
}
function FindCallBack(shapeLayer, results, positions, moreResults, e)
{
if(positions != null && positions.length > 0)
{
PlacePushPin(positions[0].
latitude = positions[0].LatLong.Latit
longitude = positions[0].LatLong.Longi
parent.document.forms[0].a
parent.document.forms[0].a
}
}
function PlacePushPin(lat, lon)
{
latlong = new VELatLong(lat,lon);
customerPushPin = new VEShape(VEShapeType.Pushpi
map.AddShape(customerPushP
map.SetCenterAndZoom(latlo
}
</script>
</head>
<body onload="GetMap();">
<onbeforeprint="beforeprin
<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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
MindenMan, care to share how you solved it? EE is such a pain, i just wasted my freebie on this post where you put "I've solved this myself."