locked
How to conditionally hide ribbon button with javascript? RRS feed

  • Question

  • Hi,

    Does anyone know how to conditionally hide a button? <EnableRule> has a <CustomRule> element, but this does not exist for <DisplayRule>. I basically want to use javascript to find the value of an attribute on a related entity <ValueRule> only looks at the current entity. So I was going to do it using something like a <CustomRule>.

    I could do it in the onLoadEvent and use the DOM document, but this is not supported by microsoft.

    Regards

    Chris

     

    Wednesday, January 18, 2012 8:58 PM

Answers

  • Hi,

    HideCustomAction would hide it unconditionally, if ribbon button has to be hidden/shown based on business logic then that could be done by using DisplayRule and a field (which is updated based on business logic).

     


    cheers, S.Khan MCTS


    Yes Chris,

    You can write javascript  for OnLoad event of form where you can set attribute value as 0 or 1 according to your business logic then call Xrm.Page.ui.RefreshRibbon() and that attribute you need to use in ValueRule in ribbon customization.

    Thank you.

    JayshriP

    • Marked as answer by ChrisAdams Thursday, January 19, 2012 2:41 PM
    Thursday, January 19, 2012 6:16 AM

All replies

  • Hi,

    yes you are right, hiding ribbon button through javascript is not supported.

    The proper way to do this is through ribbon customizations.

    You can hide/show a ribbon button based on a two options (with values 0 and 1) field, for example in your case if you set a field to 0 or 1  (may be through javascript, or .net code) based

    on your business logic and then based on the value of the field you can hide or show a ribbon button by using following diaplay rule in ribbon xml of the entity.

    <DisplayRule Id="Mscrm.Form.contact.MainTab.ButtonId.DisplayRule">        <ValueRule Field="new_optionsfield" Value="0" />            </DisplayRule>
    
    hope it helps,

     

     


    cheers, S.Khan MCTS
    Wednesday, January 18, 2012 11:09 PM
  • hi Chris,

     you dont that far to hide using javascript , this will not only unsupported but also might break something when you apply rollup patch

     here are couple of good article will take you thru how to hide ribbon

    http://dynamicscrm2011.wordpress.com/2011/05/06/ribbon-customization-part-10-hide-add-existing-button-in-dynamics-crm-2011/

    http://gtcrm.wordpress.com/2011/02/23/hiding-an-entire-group-of-ribbon-buttons-in-crm-2011/

    hth

    dkay


     if the response answered your question, please take a minute and mark the response as an answer.

    Wednesday, January 18, 2012 11:22 PM
  • Hi,

    HideCustomAction would hide it unconditionally, if ribbon button has to be hidden/shown based on business logic then that could be done by using DisplayRule and a field (which is updated based on business logic).

     


    cheers, S.Khan MCTS
    Wednesday, January 18, 2012 11:31 PM
  • Hi ChrisAdams,

     

    You can download and install the Visual Ribbbon Editor for CRM 2011 from the Codeplex using the following link.

    http://crmvisualribbonedit.codeplex.com/

    After that follow these steps.

    1. Create a JavaScript for Display Rule of that button according to your business rule.

    2. Uploaded the JavaScript to the web resources.

    3. Put that web resources link to the Display Rule of that button using the Visual Ribbon Editor.

    4. Finally Save.

     


    Regards, Kyaw Kyaw Tun
    • Edited by Kyaw Kyaw Tun Thursday, January 19, 2012 4:25 AM
    • Proposed as answer by Kyaw Kyaw Tun Thursday, January 19, 2012 4:25 AM
    Thursday, January 19, 2012 4:25 AM
  • Hi,

    HideCustomAction would hide it unconditionally, if ribbon button has to be hidden/shown based on business logic then that could be done by using DisplayRule and a field (which is updated based on business logic).

     


    cheers, S.Khan MCTS


    Yes Chris,

    You can write javascript  for OnLoad event of form where you can set attribute value as 0 or 1 according to your business logic then call Xrm.Page.ui.RefreshRibbon() and that attribute you need to use in ValueRule in ribbon customization.

    Thank you.

    JayshriP

    • Marked as answer by ChrisAdams Thursday, January 19, 2012 2:41 PM
    Thursday, January 19, 2012 6:16 AM
  • Hi,

     

    Thanks I went for this approach. I have put my logic in the onSave event though as it didn't involve a refresh.

    It seems strange that <CustomRule> is only available for <EnableRule>

     

    Thanks Jayshrip and S.Khan

     

    Thursday, January 19, 2012 2:43 PM