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

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Vikrant Upadhyay Profile Picture
    5 on at
    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
    13,216 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. 

  • Dynamics 365 Sumit Thakran Profile Picture
    110 on at
    RE: How to show/hide Ribbon Button based on view name in Dynamics 365

    OK. Thanks for quick help

  • Syed Ibrahim Profile Picture
    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

  • Dynamics 365 Sumit Thakran Profile Picture
    110 on at
    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
    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

  • Dynamics 365 Sumit Thakran Profile Picture
    110 on at
    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
    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

  • Dynamics 365 Sumit Thakran Profile Picture
    110 on at
    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
    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

Responsible AI policies

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

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
DAnny3211 Profile Picture

DAnny3211 359

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 137 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 77 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans