Search code examples
filterpowerapps

Filtering gallery based on current user


I have a gallery of draft items that I am trying to filter based on the login of the current user and uses email address from the Created By column, which is set to people or group, and does not have multiple choices in the SharePoint list - I only want the current user to see ONLY their draft items, and no one else's. The draft items show up if I'm filtering based on status, but as soon as I add the filter of the current user, it doesn't work. The ThisUser variable is populating with the logged in user. Here are my codes:

APP: OnStart: Set(ThisUser, User().Email)
GALLERY ITEMS: Filter('SP List Name', Status.Value="Draft", 'Created By'.Email=ThisUser)

I've tried many options with no luck. I'm able to see the list of drafts if I take out the line in the Filter function that has to do with email...as soon as I add the email line back in, the gallery is blank.


Solution

  • Instead of User().Email, use Office365Users.MyProfileV2().

    You will need to add the Office365Users connection to your app as well.

    So in your OnStart, set a current user variable

    Set(ThisUser, Office365Users.MyProfileV2());
    

    In your gallery, use that variable to filter your list

    Filter(
        'SP List Name', 
        Status.Value = "Draft", 
        'Created By'.Email = ThisUser.mail
    )
    

    Sometimes the result of User().Email and Office365Users.MyProfileV2().mail will be different and that's why your code won't always work