Skip to main content

Notifications

Community site session details

Community site session details

Session Id : joEYvjeeuPt8DsN4WG7+FI
Power Pages - General Discussions
Unanswered

Hide certain power pages based on web roles

Like (0) ShareShare
ReportReport
Posted on 19 Feb 2024 07:58:29 by 24

Hello, 

I have two pages one is a booking page and the other is a partner booking page. I require that for booking page it should be visible to both anonymous users and authenticated users. For the partner booking page, I have created a custom web role called the broker's role. The partner booking pages should only be visible to those users who have a broker's web role which is working fine.

However, the booking page should not be visible to users who have a broker's role which is not working.

I have tried using the web page access control rule but it is also working, the booking page is not getting hidden when users who have a broker's web role are logged in. 

How can I achieve this? 

Thanks

Categories:
  • fm_skeller Profile Picture
    277 Super User 2025 Season 1 on 21 Feb 2024 at 08:30:20
    Re: Hide certain power pages based on web roles

    @RohitAswal You don't need javascript to hide weblinks - by configuring Page Access and assigning them to specific webroles you can achieve this by out-of-the-box functionality:
    Set page permissions | Microsoft Learn

  • Inogic Profile Picture
    983 Super User 2025 Season 1 on 20 Feb 2024 at 12:10:01
    Re: Hide certain power pages based on web roles

     

    Hi @RohitAswal 

    Based on our understanding, it seems you're encountering an issue with hiding certain pages based on web roles. To address this, you can modify the visibility conditions in the header web template according to your specific requirements.

     

    Below, I've provided an example of how to hide web links based on web roles. In this example, if the user has the "Broker" web role, then the first web link (booking page) is hidden:


    <script

    src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

     

    <script

    type="text/javascript">

     

    var usersRol =

    '{{user.roles}}';

     



    console.log(usersRol);

     



    if(usersRol.includes("brokers web roleAuthenticated Users")){

     



    var containerr = $(".container")[0];

     



    $($(containerr).find(".weblink")[1]).hide();// Change the value of [] according to your web link set

     



    }

     



    // Your existing code goes here



     

     

    </script>

     

     

    Inogic_0-1708431041859.png

     

    Create a web role Brokers 

     

    Inogic_1-1708431041866.png

     

     

    To reflect the change save and sync

     

     

    Output:



    Inogic_2-1708431041870.png

     


    1. Green highlighted for who user having web role brokers
    2. Red highlighted are anonymous
    3. Blue highlighted are for authenticated user

    Thanks!

    Inogic Professional Services

    An expert technical extension for your techno-functional business needs

    Power Platform/Dynamics 365 CRM

    Drop an email at crm@inogic.com

    Service:  http://www.inogic.com/services/ 

    Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/




  • RohitAswal Profile Picture
    24 on 20 Feb 2024 at 08:03:16
    Re: Hide certain power pages based on web roles

    @Fubar , could you please show and share some screenshots of how it is done?

    Thanks

  • RohitAswal Profile Picture
    24 on 20 Feb 2024 at 07:43:34
    Re: Hide certain power pages based on web roles

    Hi @Inogic ,
    I have tried your method but I think it's not working. Here is the code that I have written 

     window.onload = function() {
        if (window.navigator.appName == "Microsoft Internet Explorer" || window.navigator.userAgent.indexOf("Trident") > 0) {
          var searchElement = document.getElementById("search");
          if (searchElement != null) searchElement.setAttribute("href", "");
        }
        hidepage()
     
    }

    function hidepage(){
        debugger;
       var userRol = '{{user.roles}}'
       console.log(userRol)
       if(userRol.includes('broker')){
        var containerr = $(".container")[0];
        $($(containerr).find(".weblink")[3]).hide();// Change the value of [] according to your web link set
       }else{
          console.log(false)
       }
     }
    even in the console.log, it is not printing anything. I am not sure if the function is working or not
  • AkshayShah Profile Picture
    59 on 20 Feb 2024 at 04:44:31
    Re: Hide certain power pages based on web roles

    Hi Rohit,

    Kindly try below link :

    https://powerapps.microsoft.com/en-us/blog/power-apps-portals-manage-page-permissions-from-portals-studio/

     

    Thanks,

    Akshay shah

  • Inogic Profile Picture
    983 Super User 2025 Season 1 on 20 Feb 2024 at 04:10:59
    Re: Hide certain power pages based on web roles

    Hi @RohitAswal ,

     

    Based on our understanding, it seems you're encountering an issue with hiding certain pages based on web roles. To address this, you can modify the visibility conditions in the header web template according to your specific requirements.

    Below, I've provided an example of how to hide web links based on web roles. In this example, if the user has the "Broker" web role, then the first web link (booking page) is hidden:

    <script

    src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script

    type="text/javascript">

    var usersRol =

    '{{user.roles}}';

    console.log(usersRol);

    if(usersRol.includes("brokers web roleAuthenticated Users")){

    var containerr = $(".container")[0];

    $($(containerr).find(".weblink")[1]).hide();// Change the value of [] according to your web link set

    }

    // Your existing code goes here

    </script>

     

    Thanks!

    Inogic Professional Services

    An expert technical extension for your techno-functional business needs

    Power Platform/Dynamics 365 CRM

    Drop an email at crm@inogic.com

    Service:  http://www.inogic.com/services/ 

    Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

  • Fubar Profile Picture
    7,867 Super User 2025 Season 1 on 19 Feb 2024 at 22:08:39
    Re: Hide certain power pages based on web roles

    By default the Authenticated User Web Role is inherited by all logged in users (it does not need to be directly assigned to the user for them to get its privileges).  What you will probably need is the Authenticated User without the access control rule, and two other Web Roles to hold each of the access control rules that you want to use to show/hide and directly assign/remove these roles when setting up the users.

    (note: there is a checkbox on the Web Role that will stop this inheritance behavior, and if using inheritance only 1 Web Role can have each respective checkbox ticked as if there are multiple Web Roles with the same checked the system will choose only 1 of them to use).

  • RohitAswal Profile Picture
    24 on 19 Feb 2024 at 11:05:54
    Re: Hide certain power pages based on web roles

    Hi,@Akshay_Shah 

    I have configured power pages enhanced model

  • AkshayShah Profile Picture
    59 on 19 Feb 2024 at 09:59:30
    Re: Hide certain power pages based on web roles

    Hi Rohit,

    You have configured Power pages or powerapps portal in the CRM?

    Thanks,

    Akshay shah

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Pages - General Discussions

#1
WarrenBelz Profile Picture

WarrenBelz 9 Most Valuable Professional

#2
Rondel Profile Picture

Rondel 6

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 4 Most Valuable Professional

Overall leaderboard