Share via


Playing around with iframes... in javascript

Display a related entity in context of the parent is old stuff and could be found little every where if you search around. But finding samples to change or modify attached child entities is not so clear. One thing that differs if you render your iframe with a related entity is that it gets loaded during the form onload. This could be used for your advantage to do validation etc (on child/related entities witout callout logic ~ offline enabled = fast GUI response) but has a price of potential slower form onload.

Well enough, heres the code samples and yes it's just samples. Copy and past to either onload or onsave of your form. Slight modifications are needed to fit your entity names or fields.

Hide "Delete" button from iframe entity depending state of picklist from main form

function myCustomLoaded()

{

if (this.readyState
== "complete")

{

hideCustomDeleteButton()

}

}

function hideCustomDeleteButton()

{

var tmp =
crmForm.all.new_dropdownvalue.SelectedText;

switch (tmp)

{

case "Stängt":

case "Förlorad
Opportunity":

case "Not Choosen
Partner":

//TODO: Change entity number 10001 to
the one in your implementation

btnDelete =
document.all.IFRAME_mycustom.contentWindow.document.all._MBdoActioncrmGrid10001delete;

if (btnDelete != null)

btnDelete.style.display = "none";

break;

}

}

//In onload of
form

document.all.IFRAME_mycustom.onreadystatechange
= myCustomLoaded;

//Just call hideCustomDeleteButton from onchange of your picklist

Hide "New" button depending state of main form

var navCustom =
document.all.nav_opportunity_new_custom;

if (navCustom != null)

{

navCustom.style.display = "none";

//tab2 is used to place this frame

if
(crmForm.all.tab2Tab.style.display == "")

{

if (crmForm.FormType ==
CRM_FORM_DISABLED || crmForm.FormType == CRM_READ_ONLY_TYPE )

//Read only no new button
even if security saying something else

var url =
"/userdefined/areas.aspx?oId=" + crmForm.ObjectId +
"&oType=3&security=1&tabSet=opportunity_new_custom";

else

//Read from security and
render depending role

var url =
"/userdefined/areas.aspx?oId=" + crmForm.ObjectId +
"&oType=3&security=852023&tabSet=opportunity_new_custom";

document.all.IFRAME_mycustom.src = url;

}

}

 

Validate rows in grid from onsave for child entity

//call checkRows
in onsave

function checkRows()

{

var r = true;

var rows =
document.all.IFRAME_mycustom.contentWindow.crmGrid.InnerGrid.rows

//Change to your
cell to verify from grid

if (typeof(rows[0].cells[2])
== "undefined" || IsNull(rows[0].cells[2]))

return AlertMessage(0);

var total = 0;

var l = rows.length;

for (var
i = 0; i < l; i++)

total = total +
parseInt(rows[i].cells[2].innerText);

if (total != 5)

r = AlertMessage(total);

return r;

}

function AlertMessage(rows)

{

alert("You need to have atleast 5 rows to complete.
Current sum of rows: " + rows + "!");

return false;

}

https://msdn2.microsoft.com/en-us/library/ms535258.aspx
https://msdn2.microsoft.com/en-us/library/ms534638.aspx

Comments

  • Anonymous
    November 12, 2007
    Great information on using jscript. Could you assist with the following? Displaying activity history in Iframe of Contacts is straightforward with the following code: var navActivityHistory; navActivityHistory = document.all.navActivityHistory; if (navActivityHistory != null) { navActivityHistory.style.display = "none"; document.all.IFRAME_HistoryFrame.src="/sfa/conts/areas.aspx?oId=" + crmForm.ObjectId + "&oType=2&security=852023&tabSet=areaActivityHistory"; } else { alert("navHistory Not Found"); } However, I would like display a related entity (Contacts) in the context of a custom entity. The custom entity is Household and would like to display the members (contacts) of the household in an iframe on the Household form. Any ides would be appreciated.

  • Anonymous
    November 13, 2007
    Thanks! Please have a look at stunnware http://www.stunnware.com/crm2/topic.aspx?id=JS17 var lookup = crmForm.all.your_lookup_field; if ((lookup != null) && (lookup.DataValue != null)) {    var objectTypeCode = lookup[0].type;    var objectId = lookup[0].id;    var url = '/userdefined/edit.aspx?id=" + objectId + '&etc=' + objectTypeCode;    window.open(url); }