locked
How to Hide Save and Close button in Toolbar RRS feed

  • Question

  • Hi all,

    I have a customized entity, and I want to hide/remove the Save and Close button in form toolbar. I did a search, and find a post to achieve similar goal. This piece of code hides Save, Followup, Recalculate, and Attach a File buttons. But it dosen't work to me. It only removes the CRM logo, everything else remains there. dose anybody have an idea?

    ============================================================================
    var Spacer = {    
        Right : 1, // hides a right spacer if it exists
        Left : 2, // hides a left spacer if it exists
        Both : 3, // and so on...
        None : 4
    }

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

    function OnCrmPageLoad()
    {
      //Configure Display when the form loads.
      ConfigreToolbarDisplay();
      //Configure the display each time a user manually changes the window width size.
      attachEvent("onresize",ConfigreToolbarDisplay);
    }

    function ConfigreToolbarDisplay()
    {
        // Opportunity toolbar buttons
        // English | German | Spanish
        ShowHideToolbarButton( "Save|Speichern|Guardar" , Spacer.None , Display.Hide );
        ShowHideToolbarButton( "Follow Up" , Spacer.Right , Display.Hide );
        ShowHideToolbarButton( "Recalculate" , Spacer.Left , Display.Hide );
        ShowHideToolbarButton( "Attach a File" , Spacer.Both , Display.Hide );
        ShowHideToolbarButton( "Follow Up" , Spacer.Right , Display.Show );
    }

    function ShowHideToolbarButton( btnTitle , spacer , state )
    {   
        if( isNullOrEmpty( document.all.mnuBar1 ) )
            return;
        if( isNullOrEmpty( btnTitle ) )
            return;
        if( isNullOrEmpty( spacer ) )
            spacer = ToolbarSpacer.None;
        if( isNullOrEmpty( state ) )
            state = ButtonDisplay.Hide;
       
        //Get all toolbar buttons
        var toolBarButtons = document.all.mnuBar1.rows[0].cells[0].childNodes[0].childNodes;
       
        //Loop through each button
        for (var i = 0 ; i < toolBarButtons.length ; i++)
        {
            var button = toolBarButtons[i];
            if( button.title.match(btnTitle) != null ||   
                button.innerText.match(btnTitle) != null)
            {            
                button.style.display = state;
                switch(spacer)
                {
                    case Spacer.Right:
                        ShowHideSpacer( button.nextSibling );
                        break;
                    case Spacer.Left:
                        ShowHideSpacer( button.previousSibling );
                        break;
                    case Spacer.Both:
                        ShowHideSpacer( button.nextSibling );
                        ShowHideSpacer( button.previousSibling );
                        break;
                }

                return;
            }
        }
        function ShowHideSpacer( btnSpacer ){
            if( !isNullOrEmpty( btnSpacer ) )
                btnSpacer.style.display = state;
        }
        function isNullOrEmpty( obj ){
            return obj == null || typeof(obj) == "undefined" || obj == "";
        }
    }

    OnCrmPageLoad();

    =================================================================================

    Thank you,

    Donna.

    Tuesday, March 23, 2010 10:51 PM

Answers

  • Use the debugger keyword with this code and step through it to see what is actually happening.

     

    For example if your Save button doesn't include one of these language values  Save|Speichern|Guardar then it won't be found to be hidden.


    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, March 23, 2010 11:38 PM
    Moderator