1

I'm using SPServices to query a SharePoint list containing 3 fields of the type PeoplePicker. They allow multiple people to be added, so i need to check if the current user is added to any of the fields.

However i can't get the query to work, as only the first statement works.

Apologies if it's hard to read the query. Building it up manually as my CAML query tool don't allow to filter on users. And i'm a newbie to CAML.

<Query> 
    <Where>
        <Or>
            <Membership Type='CurrentUserGroups'>
                <FieldRef Name='PeoplePickerFieldOne'/>
            </Membership>
            <Includes>
                <FieldRef Name='PeoplePickerFieldOne'/>
                <Value Type='Integer'>
                <UserID Type='Integer'/>
                </Value>
            </Includes>
        </Or>
        <Or>
            <Membership Type='CurrentUserGroups'>
                <FieldRef Name='PeoplePickerFieldTwo'/>
            </Membership>
            <Includes>
                <FieldRef Name='PeoplePickerFieldTwo'/>
                <Value Type='Integer'>
                <UserID Type='Integer'/>
                </Value>
            </Includes>
        </Or>
        <Or>
            <Membership Type='CurrentUserGroups'>
                <FieldRef Name='PeoplePickerFieldThree'/>
            </Membership>
            <Includes>
                <FieldRef Name='PeoplePickerFieldThree'/>
                <Value Type='Integer'>
                <UserID Type='Integer'/>
                </Value>
            </Includes>
        </Or>
    </Where>
        <OrderBy>
            <FieldRef Name='Created' />
        </OrderBy>
</Query>
1

I guess problem is with the use of multiple <Or> conditions, as in CAML query one logical operator can be used with only two operands.

You can try below CAML query if it works for you.

    <Query> 
    <Where>
        <Or>
            <Or>
                <Or>
                    <Membership Type='CurrentUserGroups'>
                        <FieldRef Name='PeoplePickerFieldOne'/>
                    </Membership>
                    <Includes>
                        <FieldRef Name='PeoplePickerFieldOne'/>
                        <Value Type='Integer'>
                        <UserID Type='Integer'/>
                        </Value>
                    </Includes>
                </Or>
                <Or>
                    <Membership Type='CurrentUserGroups'>
                        <FieldRef Name='PeoplePickerFieldTwo'/>
                    </Membership>
                    <Includes>
                        <FieldRef Name='PeoplePickerFieldTwo'/>
                        <Value Type='Integer'>
                        <UserID Type='Integer'/>
                        </Value>
                    </Includes>
                </Or>
            </Or>
            <Or>
                <Membership Type='CurrentUserGroups'>
                    <FieldRef Name='PeoplePickerFieldThree'/>
                </Membership>
                <Includes>
                    <FieldRef Name='PeoplePickerFieldThree'/>
                    <Value Type='Integer'>
                    <UserID Type='Integer'/>
                    </Value>
                </Includes>
            </Or>
        </Or>
    </Where>
    <OrderBy>
        <FieldRef Name='Created' />
    </OrderBy>
</Query>
1

Try the below CAML:

<Where> 
  <Or>
   <Or>
     <Membership Type='CurrentUserGroups'>
                <FieldRef Name='PeoplePickerFieldOne'/>
     </Membership>
     <Includes>
                <FieldRef Name='PeoplePickerFieldOne'/>
                <Value Type='Integer'>
                <UserID Type='Integer'/>
                </Value>
     </Includes>
     <Membership Type='CurrentUserGroups'>
                <FieldRef Name='PeoplePickerFieldTwo'/>
     </Membership>
     <Includes>
                <FieldRef Name='PeoplePickerFieldTwo'/>
                <Value Type='Integer'>
                <UserID Type='Integer'/>
                </Value>
     </Includes>
   </Or>
     <Membership Type='CurrentUserGroups'>
                <FieldRef Name='PeoplePickerFieldThree'/>
     </Membership>
     <Includes>
                <FieldRef Name='PeoplePickerFieldThree'/>
                <Value Type='Integer'>
                <UserID Type='Integer'/>
                </Value>
     </Includes>
  </Or>
</Where>
<OrderBy>
    <FieldRef Name='Created' />
</OrderBy>
  • Yayati were 5 minutes faster than you but have a upvote for taking your time. Thanks! – Christoffer Feb 13 '17 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.