+ Start a Discussion
Kalle KalifKalle Kalif 

Getting data on the VIEWER of dashboard for Visualforce purposes

I have a visualforce page i am using in my dashboard, where i have a SOQL query with a 

 

 where owner.id='{!$User.Id}'

argument. Is there a way of changing $User.Id to $Dashboardviewer.id or similar?

 

Now i have to log in as the relevant user to see what he sees. It would be easier to simply change to him as the viewer.

 

 

joshbirkjoshbirk

So are you saying you want the ability to easily switch the $User.Id value with another known one?  Is User done via a StandController right now, custom or extension?

Kalle KalifKalle Kalif

I simply want to know what is the correct line of code to get the id of the dashboard viewer.

 

I have no controller for my page, getting data using Ajax toolkit, i.e.:

 

  sforce.connection.sessionId = '{!$Api.Session_ID}';
var user = sforce.connection.getUserInfo();
var records = sforce.connection.query("select name, (select Approved__c, report_date__c, latdecimal__c, londecimal__c from Reports__r order by Report_date__c desc limit 1) from veh__c where owner.id='{!$User.Id}' and Id in (select veh_name__c from report__c)");

 

 

joshbirkjoshbirk

So:

 

var user = sforce.connection.getUserInfo();

 

Will always return the currently logged in user.  To get another user, you would have to run SOQL for that user based on email, name, ID, etc.

 

Do you mean a situation like this: http://boards.developerforce.com/t5/Visualforce-Development/Running-User-in-Dynamic-Dashboard/td-p/304043

 

?

Kalle KalifKalle Kalif

I have tried using the example in the post you linked to, like this

 

var dbuser = sforce.connection.query("select RunningUserId, title from Dashboard where Title='test VM'");

 but it gives my ID every time, and not the id of the user I specify in "view dashboard as", which is my goal..