Select to view content in your preferred language

Filter Entire Dashboard or Experience By Logged In User

732
4
10-12-2023 10:28 AM
JoeAbercrombie
New Contributor II

Hi there, 

I have moved to Agol from other services and I am having trouble with filtering. I have large datasets/maps that my technicians interact with, each feature is associated with a specific client. I serve interactive dashboards to these customers and they only see what features are filtered by their username/data. In other applications, this is a standard feature often called Row Level Security. I'm struggling with this on Agol, can I please get some advice on how to implement this; the mechanism, and most efficient approach ie. layer level, map level, dashboard, or experience? 

Many thanks.

4 Replies
jcarlson
MVP Esteemed Contributor

You can use a Data Expression in your dashboard, as that gives you access to user variables through the GetUser() function. You can use that to get the logged-in user's name, then apply different filters, etc., based on that value.

- Josh Carlson
Kendall County GIS
0 Kudos
JoeAbercrombie
New Contributor II

Hi there, 

Would really appreciate some elabouration or ideally screenshots of exactly where and how you add the getuser function. Thanks

ArmstKP
Regular Contributor

@JoeAbercrombie @jcarlson I haven't been able to implement this yet, either.  I have a hosted feature layer, where one of the fields is the user that feature is assigned to.  I want to be able to obtain the logged-in user with arcade and then filter the map/features to only the features they are assigned to.....

0 Kudos
DataOfficer
Regular Contributor

You can try something like this as your Data Expression

var fullname = GetUser()['fullName'] // alternatively change to ['username']
Console (fullname) // to check in the Console that the fullname is returned
var fs = FeatureSetByPortalItem( // get your feature service
    Portal('https://www.arcgis.com'),
    'itemid', //add in your itemid (e.g. '3385b003af5248e59c1fa68e1411c446')
    2, // change to relevant layer id (e.g. 0)
    ['*'],
    false
);
Console(Count(fs)) // to get number of features in feature service in Console

var filfs = Filter(fs, `AssignedUser= '${fullname}'`) // change field as needed
Console(Count(filfs)) // check in Console that it is returning the correct number of features assigned to the user
return filfs



0 Kudos