cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Filter gallery based on user

Hello!

I have a gallery and I want it to be filtered by the user. If the email adress is in the following column: Admins, administrators

I want them to be able to see it all. If their name does not match the emails from the emails in the culumn, I want them to only see the tickets that they have submitted. To see who made the ticket I have created a column with email().FullName, this is stored under: Mancotabel, Verzender

This is the code of the gallery:

 

SortByColumns(
    Search(
        Switch(selectedStatus,
            "All",MancoTabel,
            Filter(MancoTabel, 
                IsBlank(selectedStatus) ||
                Status = selectedStatus
            )
        ), 
        TextSearchBox1.Text, 
        "Ordernummer",
        "Verzender",
        "Deelorder", 
        "Extern", 
        "Product", 
        "Intern", 
        "Deelorder", 
        "Tekeningnummer", 
        "Omschrijving",
        "Status"
    ), 
    "Datum", 
    If(SortDescending1, Ascending, Descending)
)

So basically we need to put a filter over this that checks if their email is in a column and if it is, it would show all the tickets. If it wouldn't be in there I want it to filter on mancotabel, verzender and then on their full name. So they only see the tickets they created theirselves.

 

It would be awesome if someone could make this code for me and send the code 

 
1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @Anonymous ,

Add an If condition to check if the login user is Administrators or not,  save the corresponding SP list to Collection.

please try this, put it to OnStart property of App.

 

Set(VarCurrentUser, User());
If(IsEmpty(Filter(Admins, administrators = VarCurrentUser.Email)), ClearCollect(MyCol, Filter(MancoTabel, Verzender=VarCurrentUser.FullName)), ClearCollect(MyCol,MancoTabel))

 

Modify the Gallery Items property:

 

SortByColumns(
    Search(
        Switch(selectedStatus,
            "All",MyCol,
            Filter(MyCol, 
                IsBlank(selectedStatus) ||
                Status = selectedStatus
            )
        ), 
        TextSearchBox1.Text, 
        "Ordernummer",
        "Verzender",
        "Deelorder", 
        "Extern", 
        "Product", 
        "Intern", 
        "Deelorder", 
        "Tekeningnummer", 
        "Omschrijving",
        "Status"
    ), 
    "Datum", 
    If(SortDescending1, Ascending, Descending)
)

 

Hope this helps.

Sik

 

View solution in original post

12 REPLIES 12
eka24
Super User
Super User

If the email column Verzender holds all the email addresses for Users, Admin, Supervisor, then you need another column, GroupColumn before you can accomplish this dynamically.

The group column as the name suggests will do group based on the kind of user. Then the filtering will be done based on the group column.

Without group column then individual emails will be used to filter which is not dynamic.
Anonymous
Not applicable

Can't we put something on start like user=user().fullname or something like that? I do not want to create a column for all the people that use the application @eka24 

Using user=user().fullname will work perfectly. However based on your request to filter based on Admin, Supervisor and others, it will not be the best approach. Since each individual has unique email, if you have 10 workers you would have to use many IF functions. Also  anytime yo add another person or email changes, you have to change the formula.

If you insist on individual emails, it can be done.

Anonymous
Not applicable

I have an administrator table where only a few emails will be inside of. Then whenever someone created a ticket. I have their fullname stored automatically in a textfield. Is there really no easy way to lookup their fullname at the start of the application and then check the column with fullnames that have the same fullname as the user? 

@eka24 

Anonymous
Not applicable

You're not really getting me I think. 

I have a column with admins. I want these admins to be able to see all of the tickets. Now I want the other users to only see which ticket they have created. The way I save who made the ticket is by having a textbox with this "user().fullname" this gets stored in the database. I want them only be able to see the tickets where that ticket has the same fullname.

@eka24 

v-siky-msft
Community Support
Community Support

Hi @Anonymous ,

Add an If condition to check if the login user is Administrators or not,  save the corresponding SP list to Collection.

please try this, put it to OnStart property of App.

 

Set(VarCurrentUser, User());
If(IsEmpty(Filter(Admins, administrators = VarCurrentUser.Email)), ClearCollect(MyCol, Filter(MancoTabel, Verzender=VarCurrentUser.FullName)), ClearCollect(MyCol,MancoTabel))

 

Modify the Gallery Items property:

 

SortByColumns(
    Search(
        Switch(selectedStatus,
            "All",MyCol,
            Filter(MyCol, 
                IsBlank(selectedStatus) ||
                Status = selectedStatus
            )
        ), 
        TextSearchBox1.Text, 
        "Ordernummer",
        "Verzender",
        "Deelorder", 
        "Extern", 
        "Product", 
        "Intern", 
        "Deelorder", 
        "Tekeningnummer", 
        "Omschrijving",
        "Status"
    ), 
    "Datum", 
    If(SortDescending1, Ascending, Descending)
)

 

Hope this helps.

Sik

 

Anonymous
Not applicable

Thank you for your answer @eka 

The code on onstart works. However, the code for my gallery gives me an error:

https://gyazo.com/60b1e395fc0d99b0789a62fd4f541eab

"The function 'search' has some invalid arguments."
"The function 'SortByColumns' has some invalid arguments."


Hi @Anonymous ,

 

Does the original Code work?

Please go to check the MyCol collection to see if these columns in Search and SortByColumns functions exist.

Also ensure all columns in Search function must contain text.

Sik

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,547)