Asked by:
how to hide ribbon button through javascript in crm 2013

Question
-
Hi,
Can anyone tell me how to hide button through javascript by changes in css style sheet.
Friday, January 16, 2015 1:36 PM
All replies
-
Hello,
If this question is about a Ribbon button: You could think of a display rule with a custom JS function but a display rule doesn't have a custom rule element in the RibbonDiffXML(your JS function). You could use an enable rule with a custom JS function (that return true or false) (enable rule has a custom rule element in RibbonDiffXml) .
I think (almost sure) changing CSS in JavaScript is not supported.
Use enable rules: https://www.powerobjects.com/blog/2011/06/17/crm-2011-enabling-and-disabling-ribbon-buttons-2/
Hope this helps,
Kind Regards
Friday, January 16, 2015 2:18 PM -
Hello J_H_L,
I used this script on page load event in CRM 2013. Its working
function btnHide(){
var elem=top.document.getElementById("your_button_id");
elem.style.display="none";
}
Friday, January 16, 2015 2:24 PM -
Ok, but this code is unsupported, but I think you cannot hide an element on a supported way.
Interesting article: https://crmbusiness.wordpress.com/2014/01/27/why-you-shouldnt-put-unsupported-customizations-in-microsoft-dynamics-crm/ and https://msdynamicscrmblog.wordpress.com/2013/10/18/common-unsupported-customization-practices-in-dynamics-crm-2013/
Kind Regards
Edit: Hiding ribbon buttons IS possible: http://www.powerobjects.com/blog/2011/10/20/how-to-hide-a-button-on-the-ribbon-in-dynamics-crm-2011/- Edited by Jochen- Friday, January 16, 2015 2:45 PM
Friday, January 16, 2015 2:35 PM -
Use a tool like Ribbon Workbench to manipulate buttons: http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx; in your case, create an enabled rule, which calls a JS function, which determines whether the button is displayed or not.
Per
Friday, January 16, 2015 6:48 PM -
Hi,
I have created script for hide custom button on ribbon. I triggered my script on page load event. Its working but when i click on save button then all custom buttons are displaying. please tell me what should I do. I have tried my script on save event also but button still visible.
function btnHide()
{
var userId = Xrm.Page.context.getUserId();
if(userId=="{37974C5C-0E97-E411-9414-000C29DD4194}")
{
var elem=top.document.getElementById("new_proposals|NoRelationship|Form|new.new_proposals.Button1.Button");
elem.style.display="none";
var elem1=top.document.getElementById("new_proposals|NoRelationship|Form|new.new_proposals.Button3.Button");
elem1.style.display="none";
var btnApprove=top.document.getElementById("new_proposals|NoRelationship|Form|new.new_proposals.Button2.Button");
btnApprove.style.display="none";
}}
- Edited by Aamir Hijazi Monday, January 19, 2015 7:55 AM
Monday, January 19, 2015 7:54 AM