web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to get web roles o...
Power Pages
Answered

How to get web roles of signed-in user in server logic

(1) ShareShare
ReportReport
Posted on by 147
Hi! I've tried to figure out how to get the web roles of the current signed-in user in a server logic in Power Pages, but can't seem to figure it out. My goal is to get the current roles, and send that response to my SPA to filter the app based on the user's roles. 
 
I was hoping it would be available in the Server.User object, but I haven't found it. I've also tried to look manually in the Contacts table to find a column to fetch, but I can't find the column for the user's roles. And the Web Roles table only contains the roles, not which users are assigned to them. I can only see them for each contact in the Power Pages Management App > Contacts > Portal Contact (Enhanced). But how do I get that information in the server logic?
 
Can anyone point me in the right direction? Thanks! :)
I have the same question (0)
  • Suggested answer
    Valantis Profile Picture
    6,286 on at
    Hi @StineN,
     
    Web roles aren't directly on the Server.User object, but you can query them from Dataverse in server logic since the user's contact ID is available.
     
    The relationship between contacts and web roles is stored in the `mspp_webrole_contact` many-to-many intersection table. Here's how to query it in server logic:
     
    ```javascript
    const contactId = Server.User.ContactId;
    const result = await Server.Connector.Dataverse.RetrieveMultipleRecords(
        "mspp_webroleset",
        `?$filter=mspp_webrole_contact/any(c:c/contactid eq ${contactId})&$select=mspp_name,mspp_webroleid`
    );
    const roles = result.value.map(r => r.mspp_name);
    return JSON.stringify({ roles });
    ```
     
    This uses the `Server.User.ContactId` to get the current user's contact ID, then queries the web role table filtered by that contact via the intersection relationship.
    Make sure the server logic has table permissions configured to read the `mspp_webrole` table, otherwise the Dataverse call will be blocked.
     
     

     

    Best regards,

    Valantis

     

    ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/

    💼 LinkedIn

    ▶️ YouTube

  • Suggested answer
    11manish Profile Picture
    2,829 on at
    The reason you're not finding Web Roles on either Server.User or directly on the Contact table is that Power Pages stores Web Roles as a many-to-many
     
    relationship between Contacts and Web Roles, not as a column on the Contact record.
     
    How Web Roles Are Stored
    Contact ↔ Contact-Web Role Association  ↔  Web Role
    So:
    • The Contact table does not contain a "Web Role" column.
    • The Web Role table only contains role definitions.
    • The relationship is stored in an association (junction) table managed by Power Pages.
    For your scenario, create a small Liquid-based endpoint that returns user.roles as JSON, call it from your SPA, and use the returned roles for UI filtering.
     
    This is typically the easiest, most maintainable, and Power Pages-friendly solution.
  • Suggested answer
    Jerald Felix Profile Picture
    378 Super User 2026 Season 1 on at

    Hello StineN,

    Greetings! Thanks for raising this question in the Q&A forum.

    Great question! The reason you can't find Web Roles on Server.User or as a column on the Contact table is that Power Pages stores the relationship between Contacts and Web Roles as a many-to-many relationship through a junction (intersection) table called mspp_webrole_contact. So neither side of the relationship holds the data directly it lives in between them.

    Here are two approaches you can use depending on your setup:
     

    Approach 1: Query Web Roles via Server Logic (Dataverse API)

    This is the best fit if you are already using server logic to serve data to your SPA.
    Step 1: Get the current user's Contact ID from the Server.User object, which is available in server logic automatically.
    Step 2: Query the mspp_webroleset table filtered by that Contact ID using the intersection relationship, like this:
      
    javascript
    const contactId = Server.User.ContactId;
    const result = await Server.Connector.Dataverse.RetrieveMultipleRecords(
      "mspp_webroleset",
      `?$filter=mspp_webrole_contact/any(c:c/contactid eq ${contactId})&$select=mspp_name,mspp_webroleid`
    );
    const roles = result.value.map(r => r.mspp_name);
    return JSON.stringify({ roles });
     

    Step 3: Make sure the server logic has table permissions configured to allow read access on the mspp_webrole table — otherwise the Dataverse call will be blocked silently.

    Step 4: Call this server logic endpoint from your SPA and use the returned roles array to conditionally show or hide parts of your app.

     

    Approach 2: Use a Liquid-Based Web API Endpoint (Simpler Alternative)

     If you prefer a lighter approach without server logic, you can create a Liquid page template that outputs the current user's roles as JSON.
     

    Step 1: Create a new Web Template in Power Pages with the following Liquid code:

     
    {
      "roles": [
        {% for role in user.roles %}
          "{{ role.name }}"{% unless forloop.last %},{% endunless %}
        {% endfor %}
      ]
    }
     

    Step 2: Set the MIME type of the page to application/json so your SPA can consume it directly.

    Step 3: Call this page URL from your SPA using a simple fetch() request and parse the returned JSON to filter your UI based on the roles.
     
    Both approaches work well. The Liquid-based approach is simpler and requires no extra permissions setup, while the server logic approach gives you more flexibility if you need to combine role data with other server-side logic.
     

    For reference, you can read more about server logic operations here: https://learn.microsoft.com/en-us/power-pages/configure/server-logic-operations 

    If this answer helps you kindly accept the answer which will help others who have similar questions.

    Best Regards,
    Jerald Felix.

  • StineN Profile Picture
    147 on at
    Thank you for your replies, @11manish @Jerald Felix @Valantis. Have any of you actually got it working this way and testet it yourselves? I've tried it, but it doesn't work.
     
    When I try to use the $filter query parameter, I get this error message from the server logic: 
    The ?$filter query parameter is not supported
    
    
    I've also tried using $expand, but that is not supported either. I know server logic is still in preview, but I was hoping it would be possible. Did you actually test this, or did you just ask AI? 
     
    I also tried to create a Liquid web template, but how exactly do I call the web template from my SPA? I mean, what is the exact endpoint/url for a web template in Power Pages? 
     
     
     
  • Verified answer
    StineN Profile Picture
    147 on at
    I solved it. Posting it here if anyone else is looking for a working solution. 
     
    Server logic: 
     
    // Get contactid for current user 
    const contactId = Server.User.contactid;
     
    // Get the web roles using the navigation property 
    const webRolePath =`contacts(${contactId})/powerpagecomponent_mspp_webrole_contact`;
    const rolesResp = await Server.Connector.Dataverse.RetrieveMultipleRecords(webRolePath);
    const rolesData = JSON.parse(JSON.parse(rolesResp).Body).value;
     
    // Create array with only the web role name
    const roles = rolesData.map((role) => role.name)
     
    // Return JSON response to SPA
    return JSON.stringify({ status: "success", data: roles});
     
    I also created table permissions for the tables Web Role and Site Components, and assigned them to the web role to make the server logic be able to access data.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
11manish Profile Picture

11manish 42

#2
omkarsupreme Profile Picture

omkarsupreme 37

#3
Valantis Profile Picture

Valantis 35

Last 30 days Overall leaderboard