To do so we first have to load the associated view to make sure the object is available. After it is loaded we can retrieve the crmGrid object that is located inside the IFRAME. Attach a function to the onrefresh event of this control and you can start doing you coding.
Call a webservice to do some async calls or just update some fields on the CRM form.
Add this code to the OnLoad of the CRM form. Make sure you also replace the control names with your own controls. (You can easily find them using the IE Developer Toolbar)
//=========================================================================
// Author: Kenny Vaes
// Creation date: 22/05/2008
// Description: Execute client side code when an associated entity is added
//=========================================================================
try
{
var script = document.createElement("script");
script.language = "javascript";
document.getElementsByTagName('head')[0].appendChild(script);
// Create a function that will execute when the gridview of the associated entity refreshes
var GridRefresh = function()
{
var AssocGridBody = document.getElementById("areametris_incident_assetFrame").contentWindow.document.getElementById("gridBodyTable");
if (AssocGridBody)
{
var CurrentRowCount = AssocGridBody.getElementsByTagName('tr').length;
// If the current rowcount = 1 it is possible that there is no data in the grid
// In this case the grid will only contain 1 colomn
if (CurrentRowCount == 1)
{
if (AssocGridBody.getElementsByTagName('tr')[0].getElementsByTagName('td').length == 1)
{
CurrentRowCount = 0;
}
}
if (CurrentRowCount > PreviousRowCount)
{
PreviousRowCount = CurrentRowCount;
// Do Stuff...
}
}
}
//Create a function that executes after the form has loaded.
var FormLoaded = function()
{
if ((event.srcElement.readyState == "complete") (event.srcElement.readyState == "loaded")) {
var menubuttonassets = document.getElementById("navmetris_incident_asset");
if (menubuttonassets)
{
// Perform a click to open the associated view in the iframe
menubuttonassets.click();
// Set the focus back to the area screen.
loadArea('areaForm');
}
var assocView = document.getElementById("areametris_incident_assetFrame");
if (assocView)
{
// Add an event to the readystate change of the iframe
assocView.onreadystatechange = function ()
{
if (assocView.readyState == "complete")
{
// Get the gridview inside the iframe and attach an event.
var crmGridAssets = assocView.contentWindow.document.getElementById("crmGrid");
if (crmGridAssets)
{
// Attach a function to the onrefresh of the grid
crmGridAssets.attachEvent("onrefresh", GridRefresh);
var AssocGridBody = document.getElementById("areametris_incident_assetFrame").contentWindow.document.getElementById("gridBodyTable");
if (AssocGridBody)
{
PreviousRowCount = AssocGridBody.getElementsByTagName('tr').length;
if (PreviousRowCount == 1) PreviousRowCount = 0;
}
}
}
}
}
}
}
script.attachEvent("onreadystatechange", FormLoaded);
} catch (e) { alert(e); }
Geen opmerkingen:
Een reactie posten