Friday, September 5, 2008

Show / Hide Crm Form Navigation Items

MS does not provide full control over the left navigation display. Some of the items can
only be hidden using unsupported JavaScript.

I saw a few threads on the net which use document.getElementByTagName(“LI”) and traverse
the collection to hide the desired item.

The problem with that approach is the crmForm contains a lot of LI items which causes a performance hit on the page each time it loads.

The following code uses a much more direct approach which drills directly to the navigation
bar Group ( Details , Marketing , Sales , Service ).

Paste the code inside the entity onload event.

 
var Display =
{
Show : "inline",
Hide : "none"
}

var NavGroup =
{
Details : "_NA_Info",
Sales : "_NA_SFA",
Service : "_NA_CS",
Marketing : "_NA_MA"
}

function OnCrmPageLoad()
{
ToggleNavigation( NavGroup.Details , "Workflows" , Display.Hide );
ToggleNavigation( NavGroup.Marketing , "Campaigns" , Display.Hide );
}

function ToggleNavigation( group , item , display )
{
try
{

var navGroup = document.getElementById( group );
if( !navGroup ) return alert( "Navigation Group is missing" );

for( var i = 0 ; i < navGroup.nextSibling.childNodes.length ; i++ ){

var menuItem = navGroup.nextSibling.childNodes[i];
if( menuItem.childNodes[0].childNodes[1].innerText == item )menuItem.style.display = display;

}
}
catch( err )
{
//alert( "Navigation Item " + item + " is missing" );
}

}

OnCrmPageLoad();

4 comments:

WebMasterSam said...

Thanks, works great !

law said...

This is very nice however I wish it worked with custom entities as well!

Thanks!

Seil said...

Hi..How can i do similar thing in a plugin? I dont want to use javascript. Plz let me knw.

Stelmuze said...

Hi,

I often use your blog as for various enchancement with javascript. Thanks!
Maybe this snipet could be better if it would adressed multilanguage features - now it searches by a button name, which is different in different languages.