web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Ribbon workbench - hide buttons based on selected Tab

(0) ShareShare
ReportReport
Posted on by 27

Hi everyone,

 

Does anyone know if it possible to hide a ribbon button using Ribbon workbench based on the active/selected tab on a main form? 

For example, if the user selects the "Business Case" tab, hide the Save button

 

 2630.example.png

best regards,

I have the same question (0)
  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: Ribbon workbench - hide buttons based on selected Tab

    Hello,

    You can do this by adding a Custom Enable Rules to the command of the button.

    The custom enable rule is a JS function that will show/hide the button by checking the current tab name :

    function isEnabled(formCtx) {
        const currentTab = formCtx.ui.tabs.get().find(t => t.getDisplayState() === "expanded");
        return currentTab?.getName() === "tab_2";
    }

    Replace tab_2 by your tab name.

    Next, you need to refresh the command bar when you switch tabs.

    To do this, subscribe to the "tabStateChange" event on the tabs and call a JS function that does :

    function refreshRibbon(execCtx) {
        const formCtx = execCtx.getFormContext();
        formCtx.ui.refreshRibbon(false);
    }

  • Ami K Profile Picture
    27 on at
    RE: Ribbon workbench - hide buttons based on selected Tab

    Thank you very much Xavier Monin 

    I am not receiving any errors so I think the java script is correct, but I suspect I have missed a step somewhere in Ribbon workbench, because the Save button remains enabled on the specified tab.

    Context 

    I want to hide the Save button on the ribbon if the selected tab is “Business Case”

    picture1.jpg

    Applied steps

    1. I created a new web resource for the function isEnabled java script


      picture2.jpg



    2. I created a new web resource for the tab change event java script



      picture3.jpg



    3. In the form editor, I subscribed this web resource to the “Business Case” tab via the On Tab State Change event



      picture4.jpg





    4. Saved and Published


    5. In Ribbon Workbench, I right clicked the Save button from the Mscrm.Form section, selected Customise Command and created a new Enable Rule


    6. Clicked the Add Step button and selected CustomRule


      picture5.jpg


    7. For FunctionName, I entered the name of the java script function and added the web resource to the library. I left the Default and InvertResult dropdown fields blank

      4745.picture6.png

    8. Clicked the Add Enable Rule button to the Command


      5102.picture7.png




    9. Published


      picture8.jpg




    10. I refreshed the browser several times but the Save button remains enabled on the form for the Business Case tab

    picture9.jpg

  • Verified answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: Ribbon workbench - hide buttons based on selected Tab

    Did you add "CRM Parameter = PrimaryControl" in the enable rule ? isEnabled function needs it.

  • Ami K Profile Picture
    27 on at
    RE: Ribbon workbench - hide buttons based on selected Tab

    Oops. Thank you Xavier Monin

  • AsifSk Profile Picture
    8 on at
    Ribbon workbench - hide buttons based on selected Tab
    I tried the same solution but facing the error as "formCntx.ui.refreshRibbon is not a function", and i replaced it with formContext.data.refresh(). It doesn't shows any error but still the subgrid button is not hidden.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 109

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 109

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 77 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans