Thursday, December 2, 2010

Adding a CRM 4.0 Related Entity to the Main Form using IFRAME

First create your two entities and relate them together.

  • On the main form, create an iframe section
  • Create a new IFRAME, place it in the section





















URL: about:blank
  • Open the Form Properties
  • Edit Onload
  • Check Event is enabled
  • Paste the following code
var navId = "nav_new_new_assets_new_assetitem";
if(document.getElementById(navId) != null)
{
var tmp = document.getElementById(navId).onclick.toString();
tmp = tmp.substring(tmp.indexOf("'")+1, tmp.indexOf(";"));
var loadArea = tmp.substring(0, tmp.indexOf("'"));
var roleOrd = (tmp.indexOf("roleOrd") == -1) ? -1 : tmp.substring( tmp.indexOf("roleOrd"), tmp.lastIndexOf("'")).replace("\x3d", "=");
crmForm.all.IFRAME_Items.src = (roleOrd == -1) ? GetFrameSrc(loadArea) : GetFrameSrc(loadArea) + "&" + roleOrd;
}
function GetFrameSrc(tabSet)
{
if (crmForm.ObjectId != null)
{
var id = crmForm.ObjectId;
var type = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
var path = document.location.pathname.substring(0, document.location.pathname.indexOf("edit.aspx")) + "areas.aspx?";
return (path + "oId=" + id + "&oType=" + type + "&security=" + security + "&tabSet=" + tabSet);
}
else
{
return "about:blank";
}
}
  • Now there are two things we need to edit here (items in bold). 
  • First one is var navId=
    • This needs to be the related entity, but we want the navId, not the URL.
    •  Easy way to find this ID, is to use IE Developer Tools.
      • Open your main form
      • Click Tool > Developer Tools
      • Within Developer Tools, Click the ARROW (Select Element by Click)
      • Now go back to your main form and click the related entity under details
      • A New window will appear in Developer Tools, It should have highlighted the CRM Nav Subarea.
      • Locate the ID=

  • Next Change is the crmForm.all.IFRAME_Items.src
    • Make sure to use your proper iframe ID (Iframe_Items)
  • That should be it, Save and Close.
  • Publish your entity and make sure the related entity is displaying properly


No comments:

Post a Comment