Microsoft Dynamics CRM 2011 – Hide Areas of a Form

These code snippets will hide specific areas of the Form.


// Toggle the Ribbon Toolbar to Show/Hide (same as clicking the show/hide Ribbon button)
window.top.document.getElementById("minimizeribbon").fireEvent("onclick");

// Hide the Ribbon Toolbar and move the form Content area to the top of the window.
window.top.document.getElementById("crmTopBar").style.display = "none";
window.top.document.getElementById("crmContentPanel").style.top = "0px"; // Move Form Content area up to top of window, initial style.top is 135px

// Hide Left Hand Nav bar / pane
document.getElementById("crmNavBar").parentElement.style.display = "none";
document.getElementById("tdAreas").parentElement.parentElement.parentElement.parentElement.colSpan = 2;

// Hide the Breadcrumb and Record Set Toolbar
document.getElementById("recordSetToolBar").parentElement.style.display = "none";

// Hide the Form Footer Bar
document.getElementById("crmFormFooter").parentElement.style.display = "none";

 

About these ads

About Rhett Clinton MVP
Dynamics CRM MVP

22 Responses to Microsoft Dynamics CRM 2011 – Hide Areas of a Form

  1. Geert says:

    Hey, any idea how to disable custom button on a ribbon?
    Something like if form is in create mode disable button…
    Thanks

    • You can use the FormStateRule (RibbonDiffXml) which is a child element of the DisplayRule (RibbonDiffXml) of the Ribbon XML schema, for defining when a ribbon element should be shown. If you check ou the CRM 2011 SDK and search for FormStateRule (RibbonDiffXml) you will find information on the Ribbon XML Reference with guides on how to edit the XML for the Ribbon. This will be the best and supported way.

      In an unsupported way, if you locate the button element’s id in the DOM which (for example on the Account form, the Assign button) may resemble something like account|NoRelationship|Form|Mscrm.Form.account.Assign-Large, but there is no guarantee that this will always be this, you could try something like

      if(window.top.document.getElementById(“account|NoRelationship|Form|Mscrm.Form.account.Assign-Large”))
      window.top.document.getElementById(“account|NoRelationship|Form|Mscrm.Form.account.Assign-Large”).style.display = “none”;

      Anyhow, I hope this helps you out.

      Cheers,
      Rhett

  2. Pingback: Working with CRM Forms in IFrame in CRM 2011 « Nishant Rana's Weblog

  3. Stefan says:

    Toggling the ribbon toolbar did not work for me unless i used it with the setTimeout function. It seems the page is not fully loaded when the fireEvent method is executed.

    How i got it working:

    toggleRibbonbar: function () {
    setTimeout(function () { window.top.document.getElementById(“minimizeribbon”).fireEvent(“onclick”); }, 0);
    }

    • Thats great to know Stefan, thanks.

      if you’re using this in the onload event than presumeably the form scripts haven’t fully initialised yet so a setTimeout will do the trick, if you’re using this in any other form event (onsave, onchange) it should be fine without setTimeout.

      Cheers,
      Rhett

  4. cptboa says:

    Hi there,

    is it possible minimize the ribbon toolbar with JavaScript on onLoad like in this example?

    http://blog.summitgroupsoftware.com/2010/11/web-resources-in-microsoft-dynamics-crm-2011/

    Thanks in advance,
    cheers

    • The method I’ve used and have in this blog post is by using this code.

      window.top.document.getElementById(“minimizeribbon”).fireEvent(“onclick”);

      It is just like clicking the minimise ribbon button but instead just calling it through script..

      Cheers.
      Rhett

      • cptboa says:

        First thanks for your quick answer Rhett :)

        I made a JScript Web Resource, the function there is called toggleRibbonbar:

        http://pixb.de/131r/771×546/1.png.html

        Then I placed that e.g. on the account entity:

        http://pixb.de/131s/1042×542/2.png.html

        So when I open an account now, I get this error:

        http://pixb.de/131t/386×214/3.png.html

        Well which object is there expected? Any ideas? Thanks again :)

      • I think the double quotes in the script may have been corrupt, can you copy and paste the example again from this blog or simply remove the double quotes and add them back in your script file.

        Cheers,
        Rhett

      • Mohsinkhan says:

        Hi Rhett,
        I am trying to use your code.
        // Toggle the Ribbon Toolbar to Show/Hide (same as clicking the show/hide Ribbon button)
        window.top.document.getElementById(“minimizeribbon”).fireEvent(“onclick”);
        But i am not getting any changes. Can you tell me how to use the code. I created a webresource and called the function onLoad and Onsave events. But I get a error as object expected. No other function is called in OnLoad or Onsave event.
        I even changed the Quotes.

        Regards
        Mrpathan

      • This looks for the minimizeribbon element by moving to the top of the DOM and then getting the element by id.

        window.top.document.getElementById(“minimizeribbon”).fireEvent(“onclick”);

        If you use the IE developer tools (F12) then you can start script debugging and inspect the object window.top.document.getElementById(“minimizeribbon”) to see if its found. Otherwise you can also look through HTML in the IE developer tool to see where this object exists.

        Cheers,
        Rhett

      • Mohsinkhan says:

        Yeah I am Able to find it but, i dont know why i am i getting error.

  5. cptboa says:

    Thanks pal! You’re right, the double quotes were corrupt! Now your example works! Thanks again! Have a great day!

    cheers

  6. zhongyue1982 says:

    Hi, is it possible to hide all ribbon toolbar, includes dashbord?

  7. Pingback: CRM 2011 – Hiding a Form’s Header and Footer « .Net'ers

  8. Prabhu G says:

    Hi,
    This script works great for single form. When navigate to second form, its get expanded, then 3rd form its get collapsed.

    setTimeout(function () { window.top.document.getElementById(“crmRibbonManager”).control.set_isMinimized(true); }, 0);

    This script helps me.

    Regards,
    Prabhu G

  9. Moe says:

    Hi Clinton,

    Great post!

    Is this supported functionality? Would I be able to deploy a solution to CRM Online which uses the above code?

    Thank!

    • Hi Moe,

      This is not supported javascript but it should deploye to CRM Online without any problem. Be aware that future Rollups may affect the layout of the UI and break this code.

      Cheers,
      Rhett

  10. Xitij Thool says:

    worked good only If all code is copied correctly it will hide all and other thing will be hidden by CSS , but if copied only two lines IE8* crashes after Maximize.

  11. Iain Wright says:

    Is there a way to fire the hide of the toolbar on load of the CRM “homepage”?

  12. Pingback: iframe onSave Events in MS CRm 2011 | Vivek's MIcrosoft Dynamics XRM Knowledge Base (Mine ==> Preserve)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: