Published Report filtered for user's location

Ryan S
Kilo Sage

How can I have a published report filtered to only display data for the logged-in user's location?

1 ACCEPTED SOLUTION
8 REPLIES 8

Ramz
Mega Sage

Create a new Data base view using your desired table 

 

In your database table create a before query business this will display only those data according to logged in user location
When to Run - Before Query
Scripts -
(function executeRule(current, previous /*null when async*/ ) {

// Add your code here
var current_user = gs.getUserID();

var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', current_user);
usr.query();
if (usr.next()) {
current.addQuery('location=' + usr.location);
}
})(current, previous);

 

Please mark my answer correct/helpful if it resolved your query

Kieran Anson
Kilo Patron

Does the table the report is based on have a field which relates to the current logged in user? If so, you can use a dynamic filter within the report's query. 

An example for the incident table would be a query of 

Caller .is (dynamic). Me

 

"Me" being a dynamic filter option 

I'm just looking at incident table for now, but there's no dynamic operator available for the Location field. That's really what I want:  "Location is dynamic Me."