0

do you know if it's possible with CAML to write a SharePoint list view filter query to retrieve a user that is a member of a group which in turn is a member of another group i.e. nested groups?

I've got it working so that the column "Members" is filtered to show users that are members of a security group:

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

This gives me the list items where the currently logged in user is a member of a security group in the "Members" list column.

However, I'm unable to get it to go down a level further. Use case is there're users that are members of a security group which itself is a member of another security group and that one is the actual value of a field in the "Members" list column.

Any ideas?

Thanks!

0

You need to use a nested Or. The basic syntax is:

<Or>
    <!--test 1-->
    <!--test 2-->
</Or>

Which is what you have, but either or both of test 1 and 2 can themselves be a logical join (i.e. Or or And), so

<Or>
    <!--your third test goes here-->
    <Or>
        <Membership Type="CurrentUserGroups">
            <FieldRef Name="Members" />
        </Membership>
       <Eq>
            <FieldRef Name="Members" />
            <Value Type="Integer">
                <UserID/>
            </Value>
        </Eq>
    </Or>
    <!--or here-->
</Or>

So a CAML query can be either a single test at the top level or a logic join at the top level, and the logical join can join only 2 tests, but each of those tests can be a logical join too, and you can nest them as deeply as you like.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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