SharePoint Online: Filter items created by user or group of user in custom list

SharePoint-logo

In this article, I will show you How to create a query to filter items that were created by user or group of user on a SharePoint Custom List.

*Requirements: SharePoint Site with a Custom List, SharePoint Designer, CAML (optional)

Normally, if we want to filter items on a list, we will go to List Setting → Modify the target View → Add filter rules. However, these rules are so limited – we can only use [Me] and [Today] to filter items that were created by ourselves or that were created today. How about when we need to filter items that belong to a group of users? The basic filter rules won’t let you to achieve this. Fortunately, with the help of SharePoint Designer, we can easily unlock this feature.

Let’s start!

Step 1 – Open SharePoint Designer and load your SharePoint site that has the list on it. Select your list. Then, on the right panel, you will see Views. Select the one you want to have filter rules on it.

Capture

Step 2 – Modify the query code. After you click on the view, a page of code will be shown up. If you cannot edit it, press the Advanced Mode button on the Toolbar. Search for <Query> tag and start editing (you should have set basic query rules before-hand).

Capture1

Step 3 – Insert the code. Now based on your need, you will edit the query code as you wish. Our target is to Filter items that belong to a group of user. The key is to add the following syntax:

<Membership Type = “CurrentUserGroups”>
<FieldRef Name = “The field that have the group name“>
</Membership Type>

You should study a little bit about CAML query syntax as this will help you to easily build complex query.

That’s it! Now, your list will be able to filter items that were created by you or belong to group that you are a member of.

I hope this tutorial will help you to achieve your goals.

—————————————————————————————————————————————–

*Sample Query Syntax – This one will first group the items based on Priority and then on Title. It will order the items according to the most recent Due Date and then ID number. Finally, the filter rules are: Filter items that has status Open, that were Created by user or it is CC to the user – the CC field will contain the user name or the group that the user belongs to.

<Query>
<GroupBy Collapse=”TRUE” GroupLimit=”30″>
<FieldRef Name=”Priority”/>
<FieldRef Name=”LinkTitle”/>
</GroupBy>
<OrderBy>
<FieldRef Name=”Due_x0020_Date”/>
<FieldRef Name=”ID”/>
</OrderBy>
<Where>
<And>
<Eq>
<FieldRef Name=”Status”/>
<Value Type=”Text”>Open</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name=”Author”/>
<Value Type=”Integer”>
<UserID Type=”Integer”/>
</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name=”CC”/>
<Value Type=”Integer”>
<UserID Type=”Integer”/>
</Value>
</Eq>
                              <Membership Type=”CurrentUserGroups”>
                                   <FieldRef Name=”CC”/>
                              </Membership>
</Or>
</Or>
</And>
</Where>
</Query>

Anh Vo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s