Site icon @WonderLaura

The “My Groups” View

In SharePoint 2010/2013, there’s a cool little feature in task lists that lets you create a view that shows you all items assigned to any SharePoint groups that you’re a member of.  Even though it’s not as apparent in other lists, this post will show you how to accomplish it using SharePoint Designer.  This solution can be done in either SharePoint 2010 or 2013, with your corresponding version of SharePoint Designer.

  • Create a task list in SharePoint 2010 or 2013.  Notice that there’s a default view in the list called “By My Groups”.
  • Create a task, and in the Assigned To box, pick a group that you are a member of.  Create another task and assign it to a group you’re not a member of. Notice that the “By My Groups” view will only show you the tasks assigned to groups you’re in.  It doesn’t show items that are assigned to groups I’m not in, and doesn’t show items that are assigned to me individually.
    198-image_3_36F81541.png

So, it’s just a matter of hacking into the code to see what’s going on.  I have a library where I associate each item in the library with a group of people, for approvals to take place.  I want to be able to have a single view, where everyone can view their group’s items.

    1. Make sure you have a person field in your list/library, and it lets you pick people or groups.  I’m calling mine “Approver”.
    2. For your list or library where you want to add this functionality, click to create a new view.  Choose standard view.
    3. You can call the view “My Groups” or whatever you’d like.  In the filter section, just add any filter at all.  It’s not relevant and will be removed later, we’re just using it as a placeholder.  Just “Created By” is equal to [me] or anything at all.
    4. Click OK.
    5. In SharePoint Designer, click lists and libraries on the left, and click the name of your list or library.
    6. Click the name of your view in the Views section on the right.
    7. Now, the trick is to find in the code, the filter that you just created.  The whole point was to find your filter and replace it with this special filter for groups.  You’ll find a part of the code (mine’s on line 34) that has <Query><Where> in it, and it ends with </Where></Query>.  This is the filter.  Here’s what you replace that whole thing with:

      <Query><Where><Membership Type=”CurrentUserGroups”><FieldRef Name=”Approver“/></Membership></Where></Query>Notice that the field name Approver matches step 2 where I called my people field Approver.

    8. See that I put the query on its own line, even though it had originally all been crammed onto line 34.  Again, be sure to change the field name to your own, and click Save.Done!  Now, when you’re on that view, you’re only going to see the items where the “Approver” field contains a SharePoint list that you’re a member of.Added 9/3:  If you want the query to show everything that is assigned to you OR a group you’re in, you can use this syntax:<Query><Where>
      <Or>
      <Eq>
      <FieldRef Name=”Approver”/><Value Type=”Integer”><UserID/></Value>
      </Eq>
      <Membership Type=”CurrentUserGroups”><FieldRef Name=”Approver”/></Membership>
      </Or>
      </Where></Query>

8/18/2016 Update:  Tried this old post in my SharePoint Online in Office 365 tenant, and had to use this new syntax instead:

<Query><Where>
<Or>
<Membership Type=”CurrentUserGroups”>
<FieldRef Name=”AssignedTo”/>
</Membership>
<Eq>
<FieldRef Name=”AssignedTo”></FieldRef>
<Value Type=”Integer”>
<UserID/>
</Value>
</Eq>
</Or></Where></Query>

 

 

 

 


Exit mobile version