To get a related entity to display in a CRM 4.0 IFRAME, use the following code:
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_RelatedActivities.src = GetFrameSource(“Opportunity_ActivityPointers”);
crmForm.all.IFRAME_RelatedOpenQuotes.src = GetFrameSource(“opportunity_quotes”);
crmForm.all.IFRAME_RelatedOrders.src = GetFrameSource(“opportunity_sales_orders”);
To remove certain buttons from the toolbar on the related entity (within the IFRAME), use the following:
var iFrame = crmForm.all.IFRAME_RelatedOpenQuotes;
iFrame.attachEvent( “onreadystatechange” , iFrameReady);
function iFrameReady()
{
if(iFrame.readyState == “complete”)
{
//Get all of the List Elements
var lis = crmForm.all.IFRAME_RelatedOpenQuotes.contentWindow.document.getElementsByTagName(‘li’);
var i = 0;
//Loop through the list items
while (i < lis.length) {
if (lis[i].getAttribute(‘title’) == ‘Add a new Quote to this record’ || lis[i].getAttribute(‘title’) == ‘Add existing Quote to this record’)
{
//Replace the DHTML with blank tags to hide the button
lis[i].outerHTML=’<SPAN></SPAN>’
}
i = i + 1;
}
}
}
You can get the titles of the fields using an alert on the innerHTML of the document.body, or by popping it up in the loop.
If you don’t want to loop, and you know the ids of the buttons (which can be accessed using:
crmForm.all.IFRAME_RelatedOpenQuotes.contentWindow.document
.body.innerHTML
Then you can use the following simplified code:
var iFrame = crmForm.all.IFRAME_RelatedOpenQuotes;
iFrame.attachEvent( “onreadystatechange” , iFrameReady);
function iFrameReady()
{
if(iFrame.readyState != “complete”)
{return;}
crmForm.all.IFRAME_RelatedOpenQuotes.contentWindow.document.getElementById(“_MBtoplocAssocOneToMany1084opportunityquotes”).outerHTML = ‘<SPAN></SPAN>’;
crmForm.all.IFRAME_RelatedOpenQuotes.contentWindow.document.getElementById(“_MBlocAddRelatedToNonForm10843GUID”).outerHTML = ‘<SPAN></SPAN>’;
}





