Filtering List Item using CAML query in sharepoint

Contributor

I want to filter list items on the basis of Current user sharepoint group, so only list items having value in column same as sharepoint group name can display

 

I am using CAML query


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

 

But its not working, 

 

If I put some hardcoded value to compare column value its work, but currentusergroup not working.

 

following CAML work:-

 


<Where><Eq><FieldRef Name="Vendor"/><Value Type="Text">IBM</Value></Eq></Where>

 

what changes i Need to do , so CAML can fetch currentusergroup and compare it with column value of list item

6 Replies

@rautchetan27try to use the below format

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

@Sudharsan K 

 

I tried following , but its give me syntax error, something is wrong with this CAML query

 

<Where><Eq><FieldRef Name="Vendor"/><Value Type="Text"><Membership Type=\"CurrentUserGroups\"><FieldRef Name=\"Vendor\"/></Membership></Value></Eq></Where>

@Sudharsan K 

I tried following, its not throwing any error, but also not filtering.

it showing all  list items without filter

 

<Membership Type=\"CurrentUserGroups\"><FieldRef Name=\"Vendor\"/></Membership>

@Sudharsan K 

 

Can I debug CAML query if we can check correct value coming in Currentusergroups

How we can check for value

@Sudharsan K 

 

do I need to put <Where> tag?

 


<where><Membership Type=\"CurrentUserGroups\"><FieldRef Name=\"Vendor\"/></Membership></Where>

@rautchetan27 

I am really sorry for the delay, can you try using the below code

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