Filter Data and Chart based on Login

1674
14
Jump to solution
02-28-2023 11:56 PM
MuhammadNaufalIhsan
New Contributor III

Hi,

Is there anyway to filter data and chart in dashboard (or experience builder) based on the user login? The idea is when user A login, the dashboard will only shown the user A data and he/she will not be able to see the data created by other user. The rule will be also applied to charts or widgets related to the data.

Regards,

Naufal

1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Yes, there is! It's a feature we make use of in some QC dashboards, making sure that users provide additional review to the work of others, but not themselves.

To get it to work, you need to use a Data Expression. In the Arcade expression, you'll have a chance to call the function GetUser, and then use that to filter the data on the way in.

var curr_user = GetUser()['username']

var fs = FeatureSetByPortalItem(
    Portal('your portal url'),
    'itemid of the feature service',
    0, // or whatever the layer index is, if not 0
    ['*'],
    true
)

return Filter(fs, `created_user = '${curr_user}'`

The data returned by this expression will be specific to the logged in user, and will apply to all widgets which reference the same data expression. Try it out!

- Josh Carlson
Kendall County GIS

View solution in original post

14 Replies
jcarlson
MVP Esteemed Contributor

Yes, there is! It's a feature we make use of in some QC dashboards, making sure that users provide additional review to the work of others, but not themselves.

To get it to work, you need to use a Data Expression. In the Arcade expression, you'll have a chance to call the function GetUser, and then use that to filter the data on the way in.

var curr_user = GetUser()['username']

var fs = FeatureSetByPortalItem(
    Portal('your portal url'),
    'itemid of the feature service',
    0, // or whatever the layer index is, if not 0
    ['*'],
    true
)

return Filter(fs, `created_user = '${curr_user}'`

The data returned by this expression will be specific to the logged in user, and will apply to all widgets which reference the same data expression. Try it out!

- Josh Carlson
Kendall County GIS
MuhammadNaufalIhsan
New Contributor III

Hi Josh,

Thank you! I will try it.

By the way, is there any way to filter it by group that the login user is a member in it?

 

Regards,
Naufal

0 Kudos
jcarlson
MVP Esteemed Contributor

Yes, there is!

When you use the GetUser function, the object that is returned has a number of properties, not just the username. One of them is an array of groups.

Each group in the array has its own values, too.

jcarlson_0-1677853800659.png

How you use that list of groups and apply it to a filter depends on what you're wanting to do, but you could check the array for the presence of a certain group, or else just use the list of groups to filter by an attribute, etc.

- Josh Carlson
Kendall County GIS
MuhammadNaufalIhsan
New Contributor III

It works! Thanks a lot!

Although, getting group info from the array is quite tricky. But so far it works, so thank you again!

Regards,
Naufal

0 Kudos
Tweed_ShireAdmin
New Contributor III

Is there a way to do this in Experience Builder using the chart widget? I do not see an option to add in an Arcade expression anywhere when using the chart widget in Experience Builder.

0 Kudos
OlivieroVitale
Esri Contributor

Unfortunately not yet

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

We have been looking for this forever, thank you! Unfortunately I can't make it work, it keeps telling me that it's "unable to execute the Arcade script" although the test result is exactly as expected. I was further wondering how I can make this apply to the content of my map? Maybe it is so obvious that I don't see it...

Edit: I can make it work in ArcGIS Online but unfortunately not in Enterprise 11.1 and the way I see it work for the map content would be to use a selector with the filtered expression and not to put the none option so it automatically filters to that selection.

0 Kudos
PaulPetersen1
Occasional Contributor

@Nicole_Ueberschär , we are having the same issue with Portal 11.1. Did you ever find a resolution or workaround?

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Hi @PaulPetersen1 , Unfortunately I couldn't make it work in Portal 11.1.

I found in the developer console that there seems to be an issue around that it doesn't recognize the result as a featureset:

 

error predictOutputType: "Analysis not supported"
script: Write an expression that returns a FeatureSet.

 

I don't see though why the result of the expression is not be a featureset when the test inside the Arcade expression is successful. 

I am also still looking for a better way of filtering the map content itself (in 11.2 now). It works well if we have only one district for example looking at the data for that district. But if we filter on Province level (one level up) then that person is supposed to see 7 districts and with the current options I found, he will only be able to see one district when loading the dashboard. I have been breaking my brain over trying to find a way to show all 7 districts but only those 7 districts... It is ok as long as we have have only users on the same level but not from different levels 😞

0 Kudos