Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Ribbon workbench - hide buttons based on selected Tab

Posted on by 100

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,

  • AsifSk Profile Picture
    AsifSk 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.
  • Ami K Profile Picture
    Ami K 100 on at
    RE: Ribbon workbench - hide buttons based on selected Tab

    Oops. Thank you Xavier Monin

  • Verified answer
    XM-22040801-0 Profile Picture
    XM-22040801-0 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
    Ami K 100 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

  • Suggested answer
    XM-22040801-0 Profile Picture
    XM-22040801-0 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);
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans