06 May 2009

CRM 4.0 IFrame: Show Advanced Find Result View

There are many people asked about: How to show the Advanced Find result view in an IFrame? Instead of building a custom aspx page(dynamically passing parameters, see Adi's solution), I have another method to share if you don't need passing parameters into the query.

1. Build your Advanced Find query and save it, then copy the Shortcut.

2. Put a IFrame control on the Form, clear the "Restrict cross-frame scripting" checkbox.

3. Put the below code to the OnLoad() event, you need to change the IFRAME_view name and the iFrame.src (copy and paste from the step 1)

var iFrame = crmForm.all.IFRAME_view;

iFrame.src = SERVER_URL + "/advancedfind/advfind.aspx?etn=contact&QueryId=%7b3882F0FA-2B3A-DE11-BFB8-0018FE7F3A64%7d&ViewType=4230&AutoRun=True";
iFrame.attachEvent( "onreadystatechange" , Ready);

function Ready()
var iDoc = iFrame.contentWindow.document;
if(iDoc.getElementById("crmMenuBar") != null && iDoc.getElementById("btnBack") != null)
iDoc.getElementById("crmMenuBar").style.display = "none"; // hide the top menu bar
iDoc.getElementById("btnBack").style.display = "none"; // hide the bottom BACK button

CRM 4.0 IFrame: Show Entity's Associated View

It's a common requirement to show entity's associated view(1:N, N:N) in IFrame, the below code works for both 1:N and N:N relationship, it also works on both On-Premise and IFD deployment. All you need to do is find out(IE Developer Toolbar) the ID of the associated link.

The 1:N relationship needs these parameters in the request URL: oId, oType, security, tabSet
The N:N relationship needs an extra parameter: roleOrd in the request URL, which has been involved in the code.

var navId = "nav_new_new_myentity_account";

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_view.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);
return "about:blank";

Enjoy it! ;-)