Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to show/hide Ribbon Button based on view name in Dynamics 365

Posted on by 110

Hi,

I want to show / hide ribbon button based on view name . For eg , when i open contacts in Dynamics 365 , by default "My Active Contacts" view is opened and i have created another custom view "RL Contacts" . So i want to hide Ribbon button in one view i.e "My Active Contacts" and when "RL Contacts" view is opened then ribbon button should be visible.

So how can i do this?

i tried following below url where it has explained adding some enable rules in ribbon workbench . So i have tried it .This approach only disable ribbon button . it does not hide it.

I want that this ribbon button should be hidden too not only disabled.

https://community.dynamics.com/crm/b/mscrmcustomization/posts/hide-ribbon-button-based-on-view-selected

Thanks

  • Suggested answer
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    function visibilityOfButton(selectedCtrl) {

       var viewname = selectedCtrl.getViewSelector().getCurrentView().name;

       alert("view name" + viewname);

       if (viewname === "My Active Accounts")

           visible= true;

       else

           visible = false;

       return visible;  

    };

    Add this to enable rule of the button change the name of the function in the below image to your function name or the above mentioned function name.
    pastedimage1639384854305v1.png

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Hello, 

    Please refer to this screenshots. 

    3312.uci-system-view-id.png

    Use Xrm._page.getUrl() to get the Url and split to get the ID. 

  • RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    OK. Thanks for quick help

  • Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    We are facing some random controls issues on UCI as well. Keep you posted if we found solution

  • RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Hi Syed,

    When i changed my environment setting to Classic UI and refreshed , now its working . JS code is fetching view name.

    Thanks for your help.

    Any idea why its not working in Unified Interface mode ?

  • Verified answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Can you please open in classic UI and see. Meanwhile add debugger in the code and see the function triggers or not

  • RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Hi Syed,

    But i am getting error . Please check my below steps and let me know what i m doing wrong.

    Step1 :- Added  command on Custom ribbon button using Ribon Workbench 2016

    pastedimage1579851232500v1.png

    Step 2 :- Below is web resource created and added js code in text editor as shown below

    pastedimage1579851366953v2.png

    Now after publishing both ribbon workbench changes and web resource . When i am clicking on Ribbon button in Contact view , getting below error

    pastedimage1579851438822v3.png

    I can see your code screenshot , where you have written it , it does not look like in web resource editor.

    Any help will be appreciated.

    Thanks

  • Suggested answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Hi Sumit,

    I have tested that code and it works in D365 online instance.

    1184.GetViewName.png

  • RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Hi Syed,

    Thanks for your input.

    I already tried this code snippet shared by you. This only works upto CRM 2015 . It does not work in Dynamics 365.

    I got below javascript error when i used this javascript code snippet.

    Error :- object doesn't support property or method 'get_viewTitle'

    Do you have any idea what code will work in Dynamics 365 ?

  • Suggested answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    Please create command(Pass the CRM parameter to JS fucntion) and call the below JS on load to get the view name and then create a Display rule based on the view name.

    GetViewName.png

    function getViewName(selectedCtl) {
        debugger;
        var viewName = selectedCtl.get_viewTitle();
        alert(viewName);
    }

    Call the below method to return Boolean for the display rule.

    function HideButtonBasedOnViewSelected (selectedCtrl) {             
            var query = selectedCtrl.get_viewTitle();
            if (query == 'Your View Name') {
                return false;
            }
            else
                return true;
        }

    Make as Verified, if it resolved your query

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans