Some time we need to show associated view (1:N or N:N) in Iframe. I found a good article in https://community.dynamics.com/blogs/crmjimwang/comments/28067.aspx written by Jim Wang. After doing some little changes it worked like a charm for me. You can use this code for any associated view (1:N or N:N). You just need to get Left navigation item name that you can get through IE developer toolbar or Developer tools if you are using IE 8.
//Remember to change IFRAME_Name with name of iframe in your form.
//Check Form Type if it’s 1 than hide iframe.
if (crmForm.FormType == 1) {
//To hide iframe
crmForm.all.IFRAME_Name.parentNode.style.display = ‘none’;
crmForm.all.IFRAME_Name.parentNode.parentNode.style.display = ‘none’;
}
else {
//Display associated view in Iframe
var navId = “LeftNavigationItemName“; //Remember to replace this with left navigation item name
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_Name.src = (roleOrd == -1) ? GetFrameSrc(loadArea) : GetFrameSrc(loadArea) + “&” + roleOrd;
//call function onreadystatechange to remove padding and scrollbar
crmForm.all.IFRAME_Name.attachEvent(‘onreadystatechange’, RemovePadding);
}
}
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”;
}
}
//To remove padding
function RemovePadding() {
if (crmForm.all.IFRAME_Name.readyState == ‘complete’) {
var IframeObject = crmForm.all.IFRAME_Name.contentWindow.document;
IframeObject.body.scroll = “no”;
IframeObject.body.childNodes[0].rows[0].cells[0].style.padding = “0px”;
}}
Cheer 🙂
“Show Associated View in IFrame MS CRM 4.0 | Mahender
Pal” Window Treatment Ideas ended up being a incredibly
great post, . Keep posting and I am going to keep following!
Thanks for your time ,Estela