Skip to main content
Post a question

Notifications

Community site session details

Community site session details

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

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

Like (0) ShareShare
ReportReport
Posted on 22 Jan 2020 03:37:20 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
    Vikrant Upadhyay Profile Picture
    5 on 13 Dec 2021 at 08:44:20
    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,212 User Group Leader on 24 Jan 2020 at 09:02:25
    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 24 Jan 2020 at 08:43:49
    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 24 Jan 2020 at 08:41:50
    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 24 Jan 2020 at 08:22:59
    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 24 Jan 2020 at 08:03:36
    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 24 Jan 2020 at 07:38:13
    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 24 Jan 2020 at 06:15:15
    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 24 Jan 2020 at 05:47:16
    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 24 Jan 2020 at 05:41:26
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,817 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,755 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans