Skip to main content
Community site session details

Community site session details

Session Id : 7R057cKUxQoPYTrfhrMyNw
Power Apps - Microsoft Dataverse
Unanswered

Hide show tab on d365 form

Like (0) ShareShare
ReportReport
Posted on 18 Apr 2024 00:53:24 by 180

 

 

I have Tab on d365 form , which I have  to control using  security roles ,

 

How can I apply security role to Tab?

 

Thanks,

Shafqat

Categories:
  • Ram Prakash Profile Picture
    5,318 Super User 2025 Season 2 on 18 Apr 2024 at 06:43:17
    Re: Hide show tab on d365 form

    Hi @Shafdev 

     

    You can use the below code to achieve the same


    function hideTabBasedOnRole(tabName, requiredRoleName) {
     var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.roles;
     var hasRequiredRole = false;
    
     for (var i = 0; i < currentUserRoles.getLength(); i++) {
     var userRole = currentUserRoles.get(i).getName();
     if (userRole === requiredRoleName) {
     hasRequiredRole = true;
     break;
     }
     }
     if (!hasRequiredRole) {
     var tabToHide = Xrm.Page.ui.tabs.get(tabName);
     if (tabToHide) {
     tabToHide.setVisible(false); 
     } else {
     console.error("Tab '" + tabName + "' not found.");
     }
     }
    }
    

     

     

    Call the above function with

     

    hideTabBasedOnRole("tab_details", "Administrator");

     

    You can use my video for how to write JS (https://www.youtube.com/watch?v=x8kYNCkikgs)

     

    Please mark as Answer if it is helpful and provide Kudos


    Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA
    Follow me on Twitter : @rampprakashd
    Blog : https://microsoftcrmtechie.blogspot.com

     

  • pavanmanideep Profile Picture
    491 on 18 Apr 2024 at 05:16:48
    Re: Hide show tab on d365 form

    Hi @Shafdev 

     

    You can use a function like this

     

    function hideTabBasedOnRole() {
    var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.roles;
    var isAdmin = false; // Assuming a specific role is required for access

    for (var i = 0; i < currentUserRoles.getLength(); i++) {
    var roleName = currentUserRoles.get(i).getName();
    if (roleName === "Administrator") {
    isAdmin = true;
    break;
    }
    }

    if (!isAdmin) {
    Xrm.Page.ui.tabs.get("your_tab_name").setVisible(false); // Hide the tab
    }
    }

    hideTabBasedOnRole();

     

    If I have answered your question, please mark your post as Solved.

    If you like my response or got a direction forward to proceed, please give it a Thumbs Up. Appreciate your Kudos. You can accept more than one post as a solution.

     

    If you were still facing any issue or challenge, please do let me know so that I can try to check for you. Happy to help you further.

     

    Blog:https://ecellorscrm.com

     

    Cheers,

    PMDY

  • Mahendar Pal Profile Picture
    191 on 18 Apr 2024 at 04:18:25

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Featured topics

Loading complete