Forum Discussion

rautchetan27's avatar
rautchetan27
Brass Contributor
May 27, 2020

CAML query to filter List items on the basis of Current User group in sharepoint

I have List library which having column Name-Vendor, also I have differ sharepoint user groups for each vendor.

I am using CAML query to filter List items, so user can see list items belong to its vendor group only.

I am filtering List items using CAML query  where value of currentuser group will be same as Value in Column of list items-Vendor

I am using following CAML query, is this correct, I am not getting expected filter result.

 

<Where><Eq><FieldRef Name="User_ID"/><Value Type="Text">911</Value></Eq><Membership Type="CurrentUserGroups"><FieldRef Name='Vendor' /></Membership></Where>

  • Hi rautchetan27 

    Try to use the below code

    <Or>
      <Membership Type=\"CurrentUserGroups\">
        <FieldRef Name=\"AssignedTo\"/>
      </Membership>
      <Eq>
        <FieldRef Name=\"AssignedTo\"></FieldRef>
        <Value Type=\"Integer\">
          <UserID/>
        </Value>
      </Eq>
    </Or>
  • Sudharsan K's avatar
    Sudharsan K
    Steel Contributor

    Hi rautchetan27 

    Try to use the below code

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

Resources