Tuesday, August 02, 2011

CRM 4.0 - how to set 'Filter On' filter to value 'All' for Activities/History

This script is based on amazing article of Michael Höhne and updated for CRM 4.0.

Just insert following code to OnLoad event handler of form like contact and account.

function OverrideClickHandler(loadAreaId, comboname)
{
var navElement = document.getElementById('nav' + loadAreaId);
if (navElement != null)
{
navElement.onclick = function()
{
loadArea('area' + loadAreaId);
SetView(document.getElementById('area' + loadAreaId + 'Frame'), comboname);
}
}
}

SetView = function(Iframe, comboname)
{
if (Iframe != null )
{
Iframe.onreadystatechange = function()
{
if (Iframe.readyState == 'complete')
{
var frame = frames[window.event.srcElement.id];
var viewCombo = frame.document.getElementById(comboname);

if (viewCombo.readyState == "complete")
{
SetDefaultView(viewCombo, "All");
}
else
{
viewCombo.onreadystatechange = function()
{
if (this.readyState == "complete")
{
SetDefaultView(this, "All");
}
}
}
}
}
}
}

SetDefaultView = function(viewCombo, viewName)
{
if (viewCombo.value != viewName)
{
viewCombo.value = viewName;
viewCombo.FireOnChange();
}
}

OverrideClickHandler("Activities", "scheduledend");
OverrideClickHandler("ActivityHistory", "actualend");

2 comments: