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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to display user ro...
Power Pages
Unanswered

How to display user roles on site in Power Pages

(0) ShareShare
ReportReport
Posted on by 4
Hello Everyone,
In Visual Studio Code I would like to get and display the role of the currently logged in user, I log in using a local account. So far I have managed to write such code but it does not get any roles, it constantly displays that the user is not logged in:
 
<div>
  <h2>Roles of the currently logged in user:</h2>
  {% if currentUser %}
    <ul>
      {% assign userRoles = currentUser.roles | split: ',' %}
      {% for role in userRoles %}
        <li>{{ role }}</li>
      {% endfor %}
    </ul>
  {% else %}
    <p>No user data found. Check if you are logged in.</p>
  {% endif %}
</div>
Categories:
I have the same question (0)
  • Verified answer
    oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at
    Hi, where are you assigning the value to currentUser variable?
     
    this should be just user, for example:
     
     
    <div>
      <h2>Roles of the currently logged in user:</h2>
      {% if user %}
        <ul>
          {% assign userRoles = user.roles | split: ',' %}
          {% for role in userRoles %}
            <li>{{ role }}</li>
          {% endfor %}
        </ul>
      {% else %}
        <p>No user data found. Check if you are logged in.</p>
      {% endif %}
    </div>
     
  • Daniel MS Profile Picture
    4 on at
    Dziękuje Oliver, o to właśnie chodziło! Zrobiłem jeszcze drobną zmianę w kodzie i teraz wyświetla aktualne role użytkownika:
     
    <div>
      <h2>Roles of the currently logged in user:</h2>
      {% if user %}
        <ul>
          {% for role in user.roles %}
            <li>{{ role }}</li>
          {% endfor %}
        </ul>
      {% else %}
        <p>No user data found. Check if you are logged in.</p>
      {% endif %}
    </div>

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard