Forum Discussion

skakara's avatar
skakara
Microsoft Employee
10 years ago

How to find UserName in a custom visual

I'm building a custom visual and I need to identify the logged in user's email. How can I do it? Thanks

6 Replies

    • skakara's avatar
      skakara
      Microsoft Employee

      Thanks for your reply Sam!!

       

      No, I'm not looking for the USERNAME() DAX function. I'm actually looking for a simple way to get the username from my custom visual's JavaScript code.

       

      When I view the page source of the PowerBI webpage, I see the below global JavaScript object taht actually has the username.

      But I'm not 100% sure if I can rely on that object, so that it might not change in future breaking my code.

       

      var powerbi = {
              session : {
                  userInfo: {
                      name:  '[email protected]',
                      givenName: xxxxx,
                      surname: xxxxx,
                      puid: xxxxx,
                      uoid: xxxxx,
                      alternateEmail: ''
                  }
              }
          };