Microsoft Dynamics CRM 2011 – Hide Areas of a Form
September 9, 2010 21 Comments
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";




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
Pingback: Working with CRM Forms in IFrame in CRM 2011 « Nishant Rana's Weblog
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
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
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
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
Yeah I am Able to find it but, i dont know why i am i getting error.
Thanks pal! You’re right, the double quotes were corrupt! Now your example works! Thanks again! Have a great day!
cheers
Hi, is it possible to hide all ribbon toolbar, includes dashbord?
Pingback: CRM 2011 – Hiding a Form’s Header and Footer « .Net'ers
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
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
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.
Is there a way to fire the hide of the toolbar on load of the CRM “homepage”?
Hi Iain, I don’t think so, unless you modify the OOB js files.
Maybe you could try out a technique which I have never tried but maybe it could work. Add a new button to the Home ribbon and then add a custom hide rule to it that uses javascript to determine if the button should hide. In the code that you write try and access the DOM and trigger the whole toolbar to hide. It’s a long shot but better then modifying OOB files. Here is a blog post that will start you off http://howto-mscrm.blogspot.co.uk/2011/04/how-to-series-6-how-to-use-customrule.html .
Cheers,
Rhett