Membership condition for using caml in SharePoint 2013

Source: Internet
Author: User

Use the membership condition of caml in SharePoint 2013.

Membership is used to determine whether a user belongs to a certain group. It is applicable to SP group, AD group, and AD group nested in SP group.

The following filter conditions indicate that the records of the group (P group, AD group, and AD group nested in the SP group) that the current user belongs to the assignedto field are filtered out:

<Membership Type="CurrentUserGroups">    <FieldRef Name="AssginedTo"/></Membership>

The type has several values.

  • Spweb. allusers
  • Spgroup
  • Spweb. Groups
  • Currentusergroups
  • Spweb. Users
To illustrate the usage of these five values, we need some test data:
Groups:

Test owners (ID 5, including user 1)

Test members (ID 7, does not contain any user)

Subtestgroup

Users:

User 1:

Current User)

Member of "Test owners" and "subtestgroup"

User 2

Rights granted directly on the subtestsite.

A task list:

T1 assigned to user1

T2 assigned to test owners

T3 assigned to subtestgroup

T4 assigned to user2

T5 assigned to test members

Take the caml at the beginning of this article as an example. The results of different type values are as follows:

1. spweb. allusers filters tasks directly allocated to users (not through group ).

The filter result is T1 and T4.


2. spgroup: filters out the tasks directly allocated to users in a group. You must specify the group ID.

<Membership Type="SPGroup" ID="7"><FieldRef Name="AssignedTo"/></Membership>

No results for the preceding Query

<Membership Type="SPGroup" ID="7"><FieldRef Name="AssignedTo"/></Membership>
The preceding query result is T1.


3. spweb. Groups: filter out the tasks assigned to the user group (groups without sub-site points ).

<Membership Type="SPWeb.Groups"><FieldRef Name="AssignedTo"/></Membership>

Result: T2, T5


4. spweb. Users: Filter tasks assigned to users not in any user group.

<Membership Type="SPWeb.Users"><FieldRef Name="AssignedTo"/></Membership>

Result: T4


5. currentusergroups: filter the tasks assigned to the current user through the user group. Note that the tasks directly allocated to the user will not appear in the results.

<Membership Type="CurrentUserGroups"><FieldRef Name="AssignedTo"/></Membership>

Result: T2, T3

However, assignedto can be either assigned to a group or directly assigned to a user. How can we query the tasks assigned to this user, including those allocated by group or directly.

Tasks directly assigned to the current user can be queried using the following caml:

<Eq><FieldRef Name='AssginedTo'  LookupId='TRUE'/> <Value Type='Lookup'><UserID/></Value></Eq>

The result is T1.

The task assigned to this user can be queried or connected to the preceding two cases.

<Query><Where><Or><Membership Type="CurrentUserGroups">    <FieldRef Name="Audience"/></Membership><Eq><FieldRef Name='AssginedTo'  LookupId='TRUE'/> <Value Type='Lookup'><UserID/></Value></Eq></Or></Where></Query>
The result is T1, T2, and T3.

Some bloggers may ask if a group ID is the same as the user ID in this case, because the group and user are both lookup fields.

For example, if a groupA ID is 5 and the current user ID is 5, this task is assigned to groupA but not to the current user. The preceding caml can check this task.

In fact, the group ID and user ID are not repeated. You can do a small experiment:

A./_ layouts/userdisp. aspx? Id = 15 users view User information with a user ID of 15.

B. If a group ID is 5, you can access/_ layouts/userdisp. aspx? The id = 5 page will automatically jump to/_ layouts/people. aspx? Membershipgroupid = 5



Membership condition for using caml in SharePoint 2013

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.