Mandatory Related Entities

Friday, January 25th, 2008

In line with the previous post we had a situation with a related entity in an iFrame on the form.
Before the form is saved the first time the iFrame will not show up.
It should not be possible to use the “Save and Close” before the form has been saved for the first time to make sure the users are always confronted with the iFrame.
The “Save and Close” button will only be available if the iFrame is shown.
To do this we have to disable the close from the “Save and Close” commando if the form is saved for the first time.

if (crmForm.FormType==1)
{
if (event.Mode == 2)
{
alert ("You have to save the Form before the iFrame will show up");
event.returnValue = false;
crmForm.Save();
}
}
//crmForm.FormType == 1 means the form is new.
//event.Mode == 2 refers to the "Save and Close" button

Another possibility is to hide the “Save and Close” button if the form has not been saved:

if (crmForm.FormType==1)
{
document.all._MBcrmFormSaveAndClose.style.display='none';
}

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 +"&oType="+crmForm.ObjectTypeCode+"&security=852023&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).