1

In a custom list definition, I'm building a view with this query :

      <Where>
          <Or>
            <Membership Type="CurrentUserGroups">
              <FieldRef Name="MyUserField" />
            </Membership>
            <Eq>
              <FieldRef Name="MyUserField" />
              <Value Type="Integer">
                <UserID Type="Integer" />
              </Value>
            </Eq>
          </Or>
      </Where>

As you guessed, the idea is to show only items if the field MyUserField contains the current user or a group where the user is a member.

Now I would like to change my query to restrict the display to users that are not designated (directly or via membership) in a second group.

I don't see any definition nor for a Not operation in Caml, neither for a NotMembership. This is not working :

<Where>
    <And>
        <Or>
            <Membership Type="CurrentUserGroups">
                <FieldRef Name="MyUserField" />
            </Membership>
            <Eq>
                <FieldRef Name="MyUserField" />
                <Value Type="Integer">
                    <UserID Type="Integer" />
                </Value>
            </Eq>
        </Or>
        <Not>
            <Or>
                <Membership Type="CurrentUserGroups">
                    <FieldRef Name="MyUserField2" />
                </Membership>
                <Eq>
                    <FieldRef Name="MyUserField2" />
                    <Value Type="Integer">
                        <UserID Type="Integer" />
                    </Value>
                </Eq>
            </Or>
        </Not>
    </And>
</Where>

Any suggestion?

3

I just ran a query on a list in SP CAML Query Helper and I got results with this:

            <Query>
                <Where>
                    <And>
                        <Membership Type="CurrentUserGroups">
                            <FieldRef Name="AssignedTo"/>
                        </Membership>
                        <Neq>
                            <FieldRef Name="AssignedTo" />
                            <Value Type="Integer">
                                <UserID Type="Integer" />
                            </Value>
                        </Neq>
                    </And>
                </Where>
            </Query>

Using Eq I returned 0 results and using Neq I returned 1 result. This seems to what you are looking for. (Although almost a year late!)

  • Wouldn't this return the entry if the user is in the group in the field but not directly in the field? – IMTheNachoMan Oct 4 '16 at 13:17
  • This doesn't work – M.P. Aug 14 '18 at 11:12

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.