06 May 2009

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);
}
else
{
return "about:blank";
}
}



Enjoy it! ;-)

24 comments:

Stringer said...

Hi Jim

Good post - just wondered is there a way to remove the white border that surrounds the view, to make the form look a bit more seamless. Or resize the view to fill the entire IFRAME?

Thanks SB

Leigh said...

Hi SB,

After much trial and error I have managed to remove the white border from my associated view. I added the following code to the onLoad() function. Obviously replace 'training_package_notes' with your iFrame name:

//Remove the white border from the iFrame
var frameName = 'IFRAME_training_package_notes';
var objFrame = document.getElementById(frameName);
objFrame.allowTransparency=true;

Stringer said...
This comment has been removed by the author.
Stringer said...

Hi Leigh

Thanks for your help. I managed to hack and slash a solution for my immediate needs using the following code.

//Hide borders of IFRAMES
var frameName = 'IFRAME_XXX';
var objFrame = document.getElementById(frameName);
var objWindow = document.frames[frameName];
objFrame.allowTransparency=true;
objFrame.onreadystatechange = function ()
{
if (objWindow.document.readyState=='complete')
{
objWindow.document.body.style.backgroundColor='transparent';
if (objWindow.document.getElementsByTagName('BODY')[0]!=null)
{
objWindow.document.getElementsByTagName('BODY')[0].style.padding='0px';
}
if (objWindow.document.getElementsByTagName('TABLE')[0]!=null)
{
objWindow.document.getElementsByTagName('TABLE')[0].cellPadding='0';
objWindow.document.getElementsByTagName('TABLE')[0].style.border='0px';
}
}
}

Thanks SB

Leigh said...

Why do you need the additional onreadystatechange stuff?

Inderpal said...

Hi Leigh

Credit here goes to:

http://crm.atechnisch.nl/2008/01/related-entity-in-iframe/

I'm not sure what the code is doing in its entirety.

Cheers

Jim Wang said...

To Stringer: nice to know it works for you! ;-)

Jim Wang said...

To Leigh and Inderpal: Without using onreadystatechange event, you won't know when the document has been loaded in the iframe, so it's not possible to control the element inside the iframe.

Withers said...

Onclick event is causing an error. What am I supposed to be entering for what the navId equals?

all i changed was navId
Iframe_name.src, id and type

kittu said...

Hi Jim,

I used your coding. But i cannot get the result. the IF loop cannot be executed. What can i do now?

Thanks and Regards,
Venkatesh.S

jaya said...

I learned more about online money making system through your blog. I am having a nice blog about the same keyword when was I experienced about online making money through this blog.




Make Money Online



Free part Time Jobs



Part Time Jobs

Make Money online said...

You maked clear points about online business ideas through your blog and it is very useful to make money from online at home in part time jobs Thanks.




How to create Blog



How to Make Money Online



Affiliate Programs

. said...

喝花酒
酒店喝酒
暑假打工
寒假打工
酒店小姐
酒店兼職
禮服店
酒店經紀
酒店兼差
酒店
酒店經紀人
酒店現領
酒店經紀爆米花
酒店經紀
酒店打工
酒店上班
假日打工
台北酒店經紀
酒店pt
酒店pt
酒店應酬
粉味
酒店經紀PRETTY GIRL
酒店經濟
酒店經濟
晚上兼差

Mark said...

Thanks for posting this. My apologies but I am not understanding one thing about the code. Where in your sample do you point to the specific iframe? I'm assuming that somewhere in your code I need to rename the iframe.

Thanks!

酒店上班請找艾葳 said...

艾葳酒店經紀公司提供專業的酒店經紀, 酒店上班小姐,八大行業,酒店兼職,傳播妹,或者想要打工兼差打工,兼差,八大行業,酒店兼職,想去酒店上班, 日式酒店,制服酒店,ktv酒店,禮服店,整天穿得水水漂漂的,還是想去制服店日領上班小姐,水水們如果想要擁有打工工作、晚上兼差工作兼差打工假日兼職兼職工作酒店兼差兼差打工兼差日領工作晚上兼差工作酒店工作酒店上班酒店打工兼職兼差兼差工作酒店上班等,想了解酒店相關工作特種行業內容,想兼職工作日領假日兼職兼差打工、或晚班兼職想擁有鋼琴酒吧又有保障的工作嗎???又可以現領請找專業又有保障的艾葳酒店經紀公司!

艾葳酒店經紀是合法的公司工作環境高雅時尚,無業績壓力,無脫秀無喝酒壓力,高層次會員制客源,工作輕鬆,可日領現領
一般的酒店經紀只會在水水們第一次上班和領薪水時出現而已,對水水們的上班安全一點保障都沒有!艾葳酒店經紀公司的水水們上班時全程媽咪作陪,不需擔心!只提供最優質的酒店上班,酒店上班,酒店打工環境、上班條件給水水們。心動嗎!? 趕快來填寫你的酒店上班履歷表

水水們妳有缺現領、有兼職缺錢便服店的煩腦嗎?想到日本留學缺錢嗎?妳是傳播妹??想要擁有高時薪又輕鬆的賺錢,酒店和,假日打工,假日兼職賺錢的機會嗎??想實現夢想卻又缺錢沒錢嗎!??
艾葳酒店台北酒店經紀招兵買馬!!徵專業的酒店打工,想要去酒店的水水,想要短期日領,酒店日領,禮服酒店,制服店,酒店經紀,ktv酒店,便服店,酒店工作,禮服店,酒店小姐,酒店經紀人,
等相關服務 幫您快速的實現您的夢想~!!

Jodi said...

Jim,
Can you please tell me how to get the id from the selected row in the grid that is displayed in an Iframe? I got this far:

var frameDoc = document.getElementById("IFRAME_Saw").contentWindow.document;
var a = frameDoc.all['crmGrid'].InnerGrid.SelectedRecords;
var selectedItems = new Array(a.length);
for (var i=0; i < a.length; i++)
{
selectedItems[i] = a[i][0];
}

That gets me the selected item, but I need the guid id of the entity to pass to reporting services

thanks

DD said...

Hi Jim,

what if i wanna show the associated view of N:1 relationship? is it possible to do it?

Thanks,
DD

Brad said...
This comment has been removed by the author.
Brad said...

Adi, I am having issues with this working, here is what I have? Am I setting the field correctly.

How do I use this for multiple related entities?

var navId = "nav_new_contact_priorityissues";

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_priorityissues.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";
}
}

Keith said...

Hi Jim,

First off, Great posts! I used your code for the Associated views in an Iframe with great success! (until recently)

Everything was working great for about 99% of our users until about 3 weeks ago. Now every page that has this code running on it, freezes IE for about 20-30 seconds between clicks (sometimes more). The CPU spikes to about 50% while its frozen, nothing shows in a fiddler trace... really odd. Any thoughts? I've tried turning everything I can think of off, with no luck. Will have to look for another alternative if I can't get this corrected soon.

Any assistance would be greatly appreciated! Thanks!
Keith

Dipesh said...

Hi Jim,

Thank's for the code it works great. However, when I access the parent record using IFD, the iFrame has an error: "Navigation to the webpage was cancelled." Do you know what may be going on?

Jack said...

Hello,

What would be the link (IE Developer Toolbar) identification of the link?
este código é um javascript, você adiciona ele como um recurso web?

thanks

my friend's world said...

I beleive we are missing "}".

Anay Patel said...

Hi Jim,

I have created a custom entity called 'Stakeholder' which is related to company. I want to show the associated view of stakeholder in a tab on the company form.

I have looked at countless websites but it doesnt see to work, is there a problem with the code I have? or is it not possible with custom entities?

This is the code that doesnt appear to work:

function GetFrameSource(tabSet) {
if (crmForm.ObjectId != null) {

var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;

return "areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet;
}

else {
return "about:blank";
}
}

crmForm.all.IFRAME_Stakeholder.src = GetFrameSource("areaStakeholder");

If i were to use you code, and do not have the developer toolbar, how else could i find associated link, is that the ID line at the very top?