Change NavBar into iFrame

Friday, October 10th, 2008

I received a question about how to change the left NavBar into an iFrame.
After some experimentation, I have a solution:

if (document.all.tdAreas != null) {
document.all.tdAreas.parentElement.children[0].innerHTML = "<iFrame src = 'http://crm.atechnisch.nl' height = '100%'>";
}

This should also work for other parts of the screen in a similar way.

Related Entity in iFrame

Wednesday, January 16th, 2008

Related entities are not displayed directly on the form, but only via the navigation pane.
For the user this means an extra click, and more important, when they look at the form, they are not sure if a related record is present. One way to solve this is to show the associated view of the related entity in an iFrame on the form. Related entities are not available as long as the entity has not been saved. Before the entity is saved the entity can not be shown in the iFrame.
For this the script has to check if the related entity is available. This can be done by checking if the form has been saved. When the associated view of the related entity normally is shown in an iFrame the borders are the same as the borders of the normal associated view. This will cost you a lot of precious screen space. Via additional javascript lines the borders can be hidden.
In MS CRM 4.0 you can have multiple organization on one server, this means we have to put the organization name in the link of the iFrame.
The javascript code has to be placed in the onload of the entity

//first check if the user is online. If the user is online, than the organization name should be used in the link. Otherwise (if offline) the organisation name should not be used in the link.
if (IsOnline())
{
var org = "/" + ORG_UNIQUE_NAME;
}
else
{
var org = "";
}

//the first part is to hide the borders
var frameName = 'IFRAME_Name';
var objFrame = document.getElementById(frameName);
var objWindow = document.frames[frameName];
objFrame.allowTransparency=true;
objFrame.onreadystatechange = function () {
if (objWindow.document.readyState=='complete') {
objWindow.document.body.style.backgroundColor='transparent';
if (objWindow.document.getElementsByTagName('BODY')[0]!=null) {
objWindow.document.getElementsByTagName('BODY')[0].style.padding='0px';
}
if (objWindow.document.getElementsByTagName('TABLE')[0]!=null) {
objWindow.document.getElementsByTagName('TABLE')[0].cellPadding='0';
objWindow.document.getElementsByTagName('TABLE')[0].style.border='0px';
}
}
}

//setting the contents of the iframe
var navFrame2;
navFrame2 =
document.all.nav_new_new_entity_new_relatedentity;
var navWindow = document.frames['IFRAME_Name_d'];

//and checking if the entity has been saved, nor quick create, nor bulk edit
if (crmForm.FormType==1 || crmForm.FormType==5 || crmForm.FormType==6)
{
document.all.IFRAME_Name.src="about:blank";
}
else
{
if (navFrame2 != null)
{
document.all.IFRAME_Name.src= org + "/userdefined/areas.aspx?oId=" +
crmForm.ObjectId +"&amp;oType="+crmForm.ObjectTypeCode+"&amp;security=852023&amp;tabSet=new_new_entity_new_relatedentity";
navFrame2.name = navFrame2.id;
}
else{
alert("Page Not Found");
}
}

//PS Make sure the Security Setting “Restrict cross-frame scripting” is NOT enabled on the iFrame Properties form (the checkbox should be empty)  
//AND you have to change the userdefined for system entities, but who is using does…
(in the link of the parent entity you can find the solution e.g. something like ‘document.all.IFRAME_Name.src= org + “/sfa/opps/ ‘ etc).