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.
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.
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).
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“>
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.
<GroupBy Collapse=”TRUE” GroupLimit=”30″>