Monday, April 11, 2011

Display Associated Entity On Dynamics CRM Form IFrames

This blog explains you how to display an associated entity grid on the CRM form. For example if users need to see all the activities associated with a contact on the activities Tab on the Form or on the main Form. This could be achieved using some java script on the form onLoad event and is a supported approach.




This uses 3 different methods which will get the source for the frame, set the styling of the frame and hide or display items on the grid.


// Get the URL and set the Iframe source.
var url = getFrameSource('area_campaign_additional_lead') + "&roleOrd=1";
crmForm.all.IFRAME_Name.src = url;


// This method set the styling for the frame.
fixStylingInFrameSource('IFRAME_Name');


// This method do the stuff on CRM Grid to hide/display items.
fixStylingInFrameContent('IFRAME_Name');



// ----------------------------------------------------------
// getFrameSource
// Gets the source URL for a frame
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"; }
}



// ----------------------------------------------------------
// fixStylingInFrameSource
// Waits for the content window of the IFrame to be ready
function fixStylingInFrameSource(iframeID) {
var frame;

if (document.getElementById(iframeID).contentWindow.document.readyState != "complete")
{ window.setTimeout(function() { fixStylingInFrameSource(iframeID) }, 10); }
else {
frame = document.getElementById(iframeID);

// Change the background color to CRM form color

frame.contentWindow.document.body.style.backgroundColor = "#eef0f6";

// Remove the left border

frame.contentWindow.document.body.all(0).style.borderLeftStyle = "none";

// Remove padding

frame.contentWindow.document.body.all(0).all(0).all(0).all(0).style.padding = "0px";

// Make the cell the full width of the IFRAME

frame.contentWindow.document.body.all(0).style.width = "100%"

// Show the IFrame

frame.style.display = "block";
}
}



// ----------------------------------------------------------
// fixStylingInFrameContent
// Waits for the content window of the IFrame to be ready
function fixStylingInFrameContent(iframeID) {
var frame;

if (document.getElementById(iframeID).contentWindow.document.readyState != "complete")
{ window.setTimeout(function() { fixStylingInFrameContent(iframeID) }, 10); }
else {
frame = document.getElementById(iframeID);

// Some sample items on the grid which will be hidden.

var menuItem2 = frame.contentWindow.document.getElementById('gridPrint');

var menuItem3 = frame.contentWindow.document.getElementById('mailMergeTeam');

var menuItem4 = frame.contentWindow.document.getElementById('assignTeam');

var menuItem5 = frame.contentWindow.document.getElementById('moreActions');

if (menuItem2 != null) { menuItem2.style.display = 'none'; }

if (menuItem3 != null) { menuItem3.style.display = 'none'; }

if (menuItem4 != null) { menuItem4.style.display = 'none'; }

if (menuItem5 != null) { menuItem5.style.display = 'none'; }

}
}


Good Luck.
Abish

No comments: