Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
skakara
Microsoft Employee
Microsoft Employee

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 6
v-chuncz-msft
Community Support
Community Support

Hi skakara,

 

Do you mean USERNAME Function? It can return the UPN of the user using the report.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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:  'xxxxx@xxxxx.com',
                givenName: xxxxx,
                surname: xxxxx,
                puid: xxxxx,
                uoid: xxxxx,
                alternateEmail: ''
            }
        }
    };

Hi skakara,

 

Currently, playing with powerbi.session.userInfo in custom visual may not be reliable. See https://github.com/Microsoft/PowerBI-visuals/issues/412.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Do we have any update on this?

Power BI Custom Visuals API does not provide user name or user email.

We recommend to use DAX function to get user's email.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Hey @v-viig ,

is this still the case or are there other ways to get the username/-email within the visual and without passing it from outside the visual?

 

Regards

Lucmax

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.