cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

How to access context information inside a custom visual

I am building a custom visual that needs to know information about the report it is hosted in and its state. For instance I need the following:

- Username of the current user running the report

- The current filters selected in the report

- The state of any other interactions that may cause the data in the current report to change

 

For instance, say I want to display the following message in a report (using a custom visual):

"Hi <username>, you have selected <filter 1> org unit and filtered by dates <date filter value>".  

This is ofcourse a dummy example showing the information I need.

 

Is this possible?

 

Thanks Guido

5 REPLIES 5
Highlighted
Resolver II
Resolver II

Re: How to access context information inside a custom visual

Regerding the first matter, the info you are asking for is accesible via the userInfo object in the powerbi.session module(powerbi.session.userInfo). It has properties that provide you with the current user's username, given name, surname, etc...

 

As for the other two, I'm yet to find a way to get that information. I don't think there's an interface for it, though I wouldn't mind being corrected.

Highlighted
Responsive Resident
Responsive Resident

Re: How to access context information inside a custom visual

I don't know anything specifically about Custom Visuals in this context, however, the way this is normally done with standard visuals is to turn off the standard title and to display a measure whose value is dynamic text within a single item card placed above the report.  You use a series of IF and HASONEVALUE statements in the measure definition to control the text output depending on the slicer filtering or cross-filtering that has been applied by the user.

 

As I understand it, custom visuals deliver cross filtering the same as standard visualisations.

 

If it absolutely has to be integrated from within your custom visualisation, is there anyway to include such a text measure in what is passed to the visualisation?

 

Hope that helps

Highlighted
Responsive Resident
Responsive Resident

Re: How to access context information inside a custom visual

Will Thompson shows how at about 28 minutes in this presentation from Data Insights

https://www.youtube.com/watch?v=d2bZpNZ6uIA

Highlighted
Frequent Visitor

Re: How to access context information inside a custom visual

@itayrom it appears that the powerbi.session.userInfo may not work: https://github.com/Microsoft/PowerBI-visuals/issues/412  I'll try this out later today.  Thanks for the tip.

 

Thanks @Brian_M for those resources unfortunatelly it appears that custom visuals do not have access to DAX environment so I cannot use the HASONEVALUE solution.  

 

The visual I am writing actually uses this information (user, filters) to save data against an external DB.  We then retreive that information when the user has the same filter values.  So its not as simple as just a text field (sorry I was just using that as an example).

Highlighted
Resolver II
Resolver II

Re: How to access context information inside a custom visual

Oh, I see it is yet another feature blocked by the custom visual sanboxing. At the moment, there are two known official(And not very satisfying) ways to overcome this issue:

1. Using the temporary "unsandboxing" flag(adding "?sandboxVisualsEnabled=false" to pbi-service url).

2. Uploading the visual to the custom visuals gallery(because all visuals in the gallery have their code reviewed by Microsoft).

 

As noted by Bashir from the PowerBI Platform Team in the following post:

http://community.powerbi.com/t5/Developer/Custom-Visuals-Sandbox-is-coming-Here-s-what-you-need-to-k...

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Kudoed Authors