Filter Data and Chart based on Login

260
5
Jump to solution
02-28-2023 11:56 PM
Labels (1)
MuhammadNaufalIhsan
New Contributor II

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

0 Kudos
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

5 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 II

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 II

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 II

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