cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Filter a gallery by current user with a toggle

I have a canvas app in the mobile layout and I want to add a control to the top of BrowseScreen1 that will toggle a filter on BrowseGallery1 between All Items (my Data Source is an SP list) and only displaying those Created By the currently logged in User.  Please note that 'Created By'.Email does not equal User().Email, as we did not change our email addresses when we moved to O365, so unless there is a better way, I am trying to leverage 'Created By'.DisplayName and User().FullName.

 

Here's what I have:

Toggle1.OnCheck = UpdateContext({varUserRequests: Filter('SP List', 'Created By'.DisplayName = User().FullName)})

 

Toggle1.OnUncheck = UpdateContext({varUserRequests: Filter('SP List', !'Created By'.DisplayName = User().FullName)})

 

BrowseScreen1.OnVisible = Refresh('SP List'); UpdateContext({varUserRequests: !true})

 

I am getting the following error in the formula bar: "Incompatible type.  We can't evaluate your formula because the context variable types are incompatible with the types of values in other places in your app."

 

I have searched all over this forum: there are posts about filtering the gallery by User, and there are posts about setting these to a toggle, but I haven't found my specific question.  I have been on this all week, can anybody help me out please?

 

-Jake

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Filter a gallery by current user with a toggle

You could something like this:

 

Create variable in the OnStart of the App or the OnVisible of the screen with the Following formula:

Set(gvCurrentUserName; User().FullName)

 

In Gallery Items property 

If(Toggle1.Value, Filter(SPListName'Created By'.DisplayName = gvCurrentUserName), SPListName)

 

By using a variable to store the user name and using the If() to outside the Filter() you should avoid any delegation issues.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

16 REPLIES 16
Highlighted
Dual Super User
Dual Super User

Re: Filter a gallery by current user with a toggle

Hi @JRuss 

 

Share sacreenshot of error

Also, on which formula is this error

 

Highlighted
Helper II
Helper II

Re: Filter a gallery by current user with a toggle

Hi Reza,

 

The error is occuring on both OnCheck and OnUncheck for Toggle1.  Please find a screenshot attached.  Also please note that the SP List is named 'Engagement Form'.

 

-Jake

Highlighted
Dual Super User
Dual Super User

Re: Filter a gallery by current user with a toggle

Hi @JRuss 

 

Screen.Onvisible use  UpdateContext({varFilter: false})

 

Toggle1.OnCheck = UpdateContext({varFilter: true})

Toggle1.OnUncheck = UpdateContext({varFilter: false})

 

Items property of gallery use the following:

If(varFilter, 'Created By'.DisplayName = User().FullName, 'Created By'.DisplayName <> User().FullName)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Highlighted
Super User
Super User

Re: Filter a gallery by current user with a toggle

You could something like this:

 

Create variable in the OnStart of the App or the OnVisible of the screen with the Following formula:

Set(gvCurrentUserName; User().FullName)

 

In Gallery Items property 

If(Toggle1.Value, Filter(SPListName'Created By'.DisplayName = gvCurrentUserName), SPListName)

 

By using a variable to store the user name and using the If() to outside the Filter() you should avoid any delegation issues.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

Highlighted
Helper II
Helper II

Re: Filter a gallery by current user with a toggle

Hey Jeff,

 

Thanks for the response.  Unfortunately it isn't working.  Please see the screenshot.

 

-Jake

Highlighted
Helper II
Helper II

Re: Filter a gallery by current user with a toggle

Hi Reza,

 

Thanks for the response.  Unfortunately it isn't working.  Please refer to the attached screenshot.

 

-Jake

Highlighted
Dual Super User
Dual Super User

Re: Filter a gallery by current user with a toggle

Hi @JRuss 

 

so sorry 

 

try this

 

If(varFilter, Filter(SPListName,'Created By'.DisplayName = User().FullName), Filter(SPListName,'Created By'.DisplayName <> User().FullName))

 

Highlighted
Helper II
Helper II

Re: Filter a gallery by current user with a toggle

Hi Reza,

 

This is very close!  The only problem is that when Toggle1 is unchecked, only list items appear in the gallery that were not created by me.  I would like to see all list items here.  Toggle1 appears to be working properly when checked, however.

 

-Jake

Highlighted
Dual Super User
Dual Super User

Re: Filter a gallery by current user with a toggle

Hi @JRuss 

 

ok then do this

If(varFilter, Filter(SPListName,'Created By'.DisplayName = User().FullName), SPListName)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (10,456)