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

Notifications

Announcements

No record found.

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

    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

    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

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

  • Ami K Profile Picture
    27 on at

    Oops. Thank you Xavier Monin

  • AsifSk Profile Picture
    8 on at
    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.
  • Suggested answer
    CU01122259-0 Profile Picture
    2 on at
    I have tried same steps but save button is not getting hide

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 80

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans