cpatenta
cpatenta

Reputation: 37

Filter SharePoint list by "current user member of group"

I have a SharePoint online list, on a site were everybody in organization has read access. The list has 3 columns: Title, Link, Site and is a table of contents to pages from different SharePoint sites, with different members. The list is populated by Flows that triggers when a page is published and it's name follows a pattern.

For example:

Article1 | Link-to-Article1 | Financial

Article2 | Link-to-Article2 | Administration

I would like to filter this list so that every user sees only the links to the sites he is member of.

Looking at the above example, if current user is member of Financial Team but not a member of Administration, he should see only Article1.

Is it possible to do this either by SharePoint view filtering or view formatting json?

Thank you!

Upvotes: 1

Views: 2580

Answers (2)

Muhammad Abbas
Muhammad Abbas

Reputation: 409

I found the actual solution for this issue.

Using CAML query is not the solution as we want a proper view. Using CAML we are only able to get data in power shell which is of no use.

Follow these steps to achieve the goal:

1: Create a new column of Type "Person or Group" with any name say "Group Column"

2: Create a new User Group with any name say "Custom User Group"

3: When an item is created in the list, run a Power Automate flow that will loop through all the users in the user group "Custom User Group" and fill that "Group Column" with each email address.

4: Go to List Settings and Scroll down to open the Default List View. Apply [ME] filter and select "Group Column" for that filter.

You are done. Now whenever any person in that User Group will open the list. He will see all the items.

Similarly, you can create different user groups and different column in list and apply [ME] filter.

Upvotes: 0

pavelgz
pavelgz

Reputation: 36

You can add a fourth column (Group) with type User/Group to the list and populate it with group or groups, that should view it. After that you can use CAML Membership element for filtering.

Basically, your SPView.Query should be something like (if ShowForGroups is an internal name for the column, that contains groups):

<Where>
   <Or>
      <Eq>
         <FieldRef Name="ShowForGroups" />
         <Value Type="Integer">
            <UserID />
         </Value>
      </Eq>
      <Membership Type="CurrentUserGroups">
         <FieldRef Name="ShowForGroups" />
      </Membership>
   </Or>
</Where>

However, you won't be able to create such view, using SharePoint view creation page, you will need to use powershell for that.

Upvotes: 2

Related Questions