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

style='font-size:10.0pt;font-family:"Courier New";color:blue'>function style='font-size:10.0pt;font-family:"Courier New"'> myCustomLoaded()

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New";color:blue'>if style='font-size:10.0pt;font-family:"Courier New"'> (this.readyState
== "complete")

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New"'>hideCustomDeleteButton()

style='font-size:10.0pt;font-family:"Courier New"'>}

style='font-size:10.0pt;font-family:"Courier New"'>}

style='font-size:10.0pt;font-family:"Courier New"'> 

style='font-size:10.0pt;font-family:"Courier New";color:blue'>function style='font-size:10.0pt;font-family:"Courier New"'> hideCustomDeleteButton()

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New";color:blue'>var style='font-size:10.0pt;font-family:"Courier New"'> tmp =
crmForm.all.new_dropdownvalue.SelectedText;

style='font-size:10.0pt;font-family:"Courier New";color:blue'>switch style='font-size:10.0pt;font-family:"Courier New"'> (tmp)

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New";color:blue'>case style='font-size:10.0pt;font-family:"Courier New"'> "Stängt":

style='font-size:10.0pt;font-family:"Courier New";color:blue'>case style='font-size:10.0pt;font-family:"Courier New"'> "Förlorad
Opportunity":

style='font-size:10.0pt;font-family:"Courier New";color:blue'>case style='font-size:10.0pt;font-family:"Courier New"'> "Not Choosen
Partner":

style='font-size:10.0pt;font-family:"Courier New"'> //TODO: Change entity number 10001 to
the one in your implementation

style='font-size:10.0pt;font-family:"Courier New"'> btnDelete =
document.all.IFRAME_mycustom.contentWindow.document.all._MBdoActioncrmGrid10001delete;

style='font-size:10.0pt;font-family:"Courier New"'> if (btnDelete != style='color:blue'>null)

style='font-size:10.0pt;font-family:"Courier New"'> btnDelete.style.display = "none";

style='font-size:10.0pt;font-family:"Courier New"'> break;

style='font-size:10.0pt;font-family:"Courier New"'>}

style='font-size:10.0pt;font-family:"Courier New"'>}

style='font-size:10.0pt;font-family:"Courier New"'> 

style='font-size:10.0pt;font-family:"Courier New";color:green'>//In onload of
form

style='font-size:10.0pt;font-family:"Courier New"'>document.all.IFRAME_mycustom.onreadystatechange
= myCustomLoaded;

style='font-size:10.0pt;font-family:"Courier New";color:green'>//Just call hideCustomDeleteButton from onchange of your picklist

Hide “New” button depending state of main form

style='font-size:10.0pt;font-family:"Courier New";color:blue'>var style='font-size:10.0pt;font-family:"Courier New"'> navCustom =
document.all.nav_opportunity_new_custom;

style='font-size:10.0pt;font-family:"Courier New";color:blue'>if style='font-size:10.0pt;font-family:"Courier New"'> (navCustom != style='color:blue'>null)

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New"'> navCustom.style.display = "none"; style='mso-tab-count:5'>

style='font-size:10.0pt;font-family:"Courier New"'> //tab2 is used to place this frame

style='font-size:10.0pt;font-family:"Courier New"'> if
(crmForm.all.tab2Tab.style.display == "")

style='font-size:10.0pt;font-family:"Courier New"'> {

style='font-size:10.0pt;font-family:"Courier New"'> if (crmForm.FormType ==
CRM_FORM_DISABLED || crmForm.FormType == CRM_READ_ONLY_TYPE )

style='font-size:10.0pt;font-family:"Courier New"'> //Read only no new button
even if security saying something else

style='font-size:10.0pt;font-family:"Courier New"'> var url =
"/userdefined/areas.aspx?oId=" + crmForm.ObjectId +
"&oType=3&security=1&tabSet=opportunity_new_custom";

style='font-size:10.0pt;font-family:"Courier New"'> else style='mso-tab-count:3'>

style='font-size:10.0pt;font-family:"Courier New"'> //Read from security and
render depending role

style='font-size:10.0pt;font-family:"Courier New"'> var url =
"/userdefined/areas.aspx?oId=" + crmForm.ObjectId +
"&oType=3&security=852023&tabSet=opportunity_new_custom"; style='mso-tab-count:5'>

style='font-size:10.0pt;font-family:"Courier New"'> document.all.IFRAME_mycustom.src = url; style='mso-tab-count:4'>

style='font-size:10.0pt;font-family:"Courier New"'> }

style='font-size:10.0pt;font-family:"Courier New"'>}

 

Validate rows in grid from onsave for child entity

style='font-size:10.0pt;font-family:"Courier New";color:green'>//call checkRows
in onsave

style='font-size:10.0pt;font-family:"Courier New";color:blue'>function style='font-size:10.0pt;font-family:"Courier New"'> checkRows()

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New";color:blue'>var style='font-size:10.0pt;font-family:"Courier New"'> r = true;

style='font-size:10.0pt;font-family:"Courier New";color:blue'>var style='font-size:10.0pt;font-family:"Courier New"'> rows =
document.all.IFRAME_mycustom.contentWindow.crmGrid.InnerGrid.rows

style='font-size:10.0pt;font-family:"Courier New";color:green'>//Change to your
cell to verify from grid

style='font-size:10.0pt;font-family:"Courier New";color:blue'>if style='font-size:10.0pt;font-family:"Courier New"'> (typeof(rows[0].cells[2])
== "undefined" || IsNull(rows[0].cells[2]))

style='font-size:10.0pt;font-family:"Courier New"'> return AlertMessage(0); style='mso-tab-count:2'>

style='font-size:10.0pt;font-family:"Courier New";color:blue'>var style='font-size:10.0pt;font-family:"Courier New"'> total = 0;

style='font-size:10.0pt;font-family:"Courier New"'> 

style='font-size:10.0pt;font-family:"Courier New";color:blue'>var style='font-size:10.0pt;font-family:"Courier New"'> l = rows.length;

lang=SV style='font-size:10.0pt;font-family:"Courier New";color:blue;
mso-ansi-language:SV'>for (var
i = 0; i < l; i++)

lang=SV style='font-size:10.0pt;font-family:"Courier New";mso-ansi-language:
SV'> total = total +
parseInt(rows[i].cells[2].innerText);

style='font-size:10.0pt;font-family:"Courier New";color:blue'>if style='font-size:10.0pt;font-family:"Courier New"'> (total != 5)

style='font-size:10.0pt;font-family:"Courier New"'> r = AlertMessage(total);

style='font-size:10.0pt;font-family:"Courier New"'>

style='font-size:10.0pt;font-family:"Courier New";color:blue'>return style='font-size:10.0pt;font-family:"Courier New"'> r;

style='font-size:10.0pt;font-family:"Courier New"'>}

style='font-size:10.0pt;font-family:"Courier New"'> 

style='font-size:10.0pt;font-family:"Courier New";color:blue'>function style='font-size:10.0pt;font-family:"Courier New"'> AlertMessage(rows)

style='font-size:10.0pt;font-family:"Courier New"'>{

style='font-size:10.0pt;font-family:"Courier New"'> alert("You need to have atleast 5 rows to complete.
Current sum of rows: " + rows + "!");

style='font-size:10.0pt;font-family:"Courier New"'> return false;

style='font-size:10.0pt;font-family:"Courier New"'>}

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

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

Comments (2)

  1. dmbrandon says:

    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.

  2. 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);

    }