web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filtering SP list coll...
Power Apps
Unanswered

Filtering SP list collection items by current user

(0) ShareShare
ReportReport
Posted on by

I'm using SharePoint list to show the list items in gallery list and it's possible to create new items to the list in app. I'm filtering collection of SP list by the author of list item and current user of the app. Also I have specified some users to see all items by email.

For me, this filtering is working correctly. The problem is that the filtering isn't working when other users are using the app.  Other users can add new items to the list successfully in app and they can see all SP list items, if I remove the current user filter from my app (see below).

I'm using filteredCollection as Items in Gallery. Here is my code at OnStart():

 

Set(
 currentUser;
 User()
);;
// get all list items
ClearCollect(
 allItemsCollection;
 MySPList
);;
If(
 // users, who can see all the list items
 currentUser.Email = "myemail@example.com" Or currentUser.Email = "boss_email@example.com";
 ClearCollect(
 filteredCollection;
 allItemsCollection
 );
 // filter items by current user
 ClearCollect(
 filteredCollection;
 Filter(
 allItemsCollection;
 Author.Email = currentUser.Email
 )
 )
)

 

 

Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @Anonymous 

     

    Can you try to update the expression to:

    Set(
    currentUser;
    User()
    );;
    If(
    currentUser.Email in ["myemail@example.com","boss_email@example.com"];
    ClearCollect(
    filteredCollection;
    MySPList
    );
    ClearCollect(
    filteredCollection;
    Filter(
    MySPList;
    Author.Email = currentUser.Email
    )
    )
    )

    Here, you can eliminate the creation of allItemsCollection and get the data directly from the SP list.

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Community Power Platform Member Profile Picture
    on at

    Hey @yashag2255 !

    Thanks for fast reply. I just was wondering that is there some difference between using operators "=" and "in" when comparing strings? I guess I should try also changing in my code to "Author.Email in currentUser.Email".  I will try this and come back with results. 🙂

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @Anonymous 

     

    In operator is used to search a value in the array list. Usage totally depends on whether an array or string is returned. If Author.Email returns a string and currentUser.Email return a string, it is okay to use =, but if you had allowed multiple authors, then you might want to change this to: currentUser.Email in Author.Email, as Author.Email will return emails of multiple selections in the authors.

     

    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • v-xida-msft Profile Picture
    on at

    Hi @Anonymous ,

    Could you please share a bit more about the "Author" column in your SP List? Is it a custom Person type column?

     

    If you want to filter your Gallery Items based on the creator of the List items, I think there is something wrong with your formula. I have made a test on my side, please consider take a try with the following workaround:

    Modify the formula within the OnStart property of the App to following:

    Set(
     currentUser;
     User()
    );;
    // get all list items
    ClearCollect(
     allItemsCollection;
     MySPList
    );;
    If(
     // users, who can see all the list items
     currentUser.Email = "myemail@example.com" || currentUser.Email = "boss_email@example.com";
     ClearCollect(
     filteredCollection;
     allItemsCollection
     );
     // filter items by current user
     ClearCollect(
     filteredCollection;
     Filter(
     allItemsCollection;
     'Created By'.Email = currentUser.Email // Modify formula here. Type 'Created By' email rather than Author.Email
     )
     )
    )

    Note: If the "Author" column that you mentioned represents the System person field in your SP List, you could not reference it using "Author" column, instead, you should use 'Created By' column.

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • Community Power Platform Member Profile Picture
    on at

    @v-xida-msft  I'm using PowerApps in Finnish language, so I guess that's the reason I don't get 'Created By' column to my collection, which seems weird. I can  only see the Author (and Editor) columns with normal properties like DisplayName, Email etc when I check the SP list collection data. Edit: I changed the language preference to English and I can select 'Created By' info from collection. This didn't solve the main problem. 😞

    @yashag2255Your solution didn't make a difference.

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @Anonymous 

     

    Can you share more information about the issue that you are seeing now? Do you mean other users are able to see data that they shouldn't?

     

    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Community Power Platform Member Profile Picture
    on at

    Other users don't see any data, even the users who should see all the items like the user "boss_email@example.com" used in the code.

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    HI @Anonymous 

     

    Can you try to update the expression to:

    Set(currentUser;User().Email);;
    If(
    currentUser in ["myemail@example.com","boss_email@example.com"];
    ClearCollect(filteredCollection;MySPList);
    ClearCollect(filteredCollection;Filter(MySPList;Author.Email = currentUser))
    )
    
    or
    
    Set(currentUser;User().Email);;
    If(
    currentUser in ["myemail@example.com","boss_email@example.com"];
    ClearCollect(filteredCollection;MySPList);
    ClearCollect(filteredCollection;Filter(MySPList;currentUser in Author.Email))
    )

    Note: Make sure that you are using filteredCollection to show the data in the app.

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard