Filtering List Item using CAML query in sharepoint

%3CLINGO-SUB%20id%3D%22lingo-sub-1415904%22%20slang%3D%22en-US%22%3EFiltering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1415904%22%20slang%3D%22en-US%22%3E%3CP%3EI%20want%20to%20filter%20list%20items%20on%20the%20basis%20of%20Current%20user%20sharepoint%20group%2C%20so%20only%20list%20items%20having%20value%20in%20column%20same%20as%20sharepoint%20group%20name%20can%20display%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20using%20CAML%20query%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CWHERE%3E%3CEQ%3E%3CFIELDREF%20name%3D%22%26quot%3BVendor%26quot%3B%2F%22%3E%3CVALUE%20type%3D%22%26quot%3BText%26quot%3B%22%3E%3CMEMBERSHIP%20type%3D%22%26quot%3BCurrentUserGroups%26quot%3B%22%3E%3C%2FMEMBERSHIP%3E%3C%2FVALUE%3E%3C%2FFIELDREF%3E%3C%2FEQ%3E%3C%2FWHERE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20its%20not%20working%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20put%20some%20hardcoded%20value%20to%20compare%20column%20value%20its%20work%2C%20but%20currentusergroup%20not%20working.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Efollowing%20CAML%20work%3A-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CWHERE%3E%3CEQ%3E%3CFIELDREF%20name%3D%22%26quot%3BVendor%26quot%3B%2F%22%3E%3CVALUE%20type%3D%22%26quot%3BText%26quot%3B%22%3EIBM%3C%2FVALUE%3E%3C%2FFIELDREF%3E%3C%2FEQ%3E%3C%2FWHERE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhat%20changes%20i%20Need%20to%20do%20%2C%20so%20CAML%20can%20fetch%20currentusergroup%20and%20compare%20it%20with%20column%20value%20of%20list%20item%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1415904%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417052%22%20slang%3D%22en-US%22%3ERe%3A%20Filtering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417052%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F670519%22%20target%3D%22_blank%22%3E%40rautchetan27%3C%2FA%3Etry%20to%20use%20the%20below%20format%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CMEMBERSHIP%20type%3D%22%5C%26quot%3BCurrentUserGroups%5C%26quot%3B%22%3E%0A%20%20%3CFIELDREF%20name%3D%22%5C%26quot%3BAssignedTo%5C%26quot%3B%2F%22%3E%0A%3C%2FFIELDREF%3E%3C%2FMEMBERSHIP%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417089%22%20slang%3D%22en-US%22%3ERe%3A%20Filtering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417089%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20following%20%2C%20but%20its%20give%20me%20syntax%20error%2C%20something%20is%20wrong%20with%20this%20CAML%20query%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CWHERE%3E%3CEQ%3E%3CFIELDREF%20name%3D%22%26quot%3BVendor%26quot%3B%2F%22%3E%3CVALUE%20type%3D%22%26quot%3BText%26quot%3B%22%3E%3CMEMBERSHIP%20type%3D%22%5C%26quot%3BCurrentUserGroups%5C%26quot%3B%22%3E%3CFIELDREF%20name%3D%22%5C%26quot%3BVendor%5C%26quot%3B%2F%22%3E%3C%2FFIELDREF%3E%3C%2FMEMBERSHIP%3E%3C%2FVALUE%3E%3C%2FFIELDREF%3E%3C%2FEQ%3E%3C%2FWHERE%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417105%22%20slang%3D%22en-US%22%3ERe%3A%20Filtering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417105%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20following%2C%20its%20not%20throwing%20any%20error%2C%20but%20also%20not%20filtering.%3C%2FP%3E%3CP%3Eit%20showing%20all%26nbsp%3B%20list%20items%20without%20filter%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CMEMBERSHIP%20type%3D%22%5C%26quot%3BCurrentUserGroups%5C%26quot%3B%22%3E%3CFIELDREF%20name%3D%22%5C%26quot%3BVendor%5C%26quot%3B%2F%22%3E%3C%2FFIELDREF%3E%3C%2FMEMBERSHIP%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417113%22%20slang%3D%22en-US%22%3ERe%3A%20Filtering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417113%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20I%20debug%20CAML%20query%20if%20we%20can%20check%20correct%20value%20coming%20in%20Currentusergroups%3C%2FP%3E%3CP%3EHow%20we%20can%20check%20for%20value%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1419601%22%20slang%3D%22en-US%22%3ERe%3A%20Filtering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1419601%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Edo%20I%20need%20to%20put%20%3CWHERE%3E%20tag%3F%3C%2FWHERE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CWHERE%3E%3CMEMBERSHIP%20type%3D%22%5C%26quot%3BCurrentUserGroups%5C%26quot%3B%22%3E%3CFIELDREF%20name%3D%22%5C%26quot%3BVendor%5C%26quot%3B%2F%22%3E%3C%2FFIELDREF%3E%3C%2FMEMBERSHIP%3E%3C%2FWHERE%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1429250%22%20slang%3D%22en-US%22%3ERe%3A%20Filtering%20List%20Item%20using%20CAML%20query%20in%20sharepoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429250%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F670519%22%20target%3D%22_blank%22%3E%40rautchetan27%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20really%20sorry%20for%20the%20delay%2C%20can%20you%20try%20using%20the%20below%20code%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3COR%3E%0A%20%20%3CMEMBERSHIP%20type%3D%22%5C%26quot%3BCurrentUserGroups%5C%26quot%3B%22%3E%0A%20%20%20%20%3CFIELDREF%20name%3D%22%5C%26quot%3BAssignedTo%5C%26quot%3B%2F%22%3E%0A%20%20%3C%2FFIELDREF%3E%0A%20%20%3CEQ%3E%0A%20%20%20%20%3CFIELDREF%20name%3D%22%5C%26quot%3BAssignedTo%5C%26quot%3B%22%3E%3C%2FFIELDREF%3E%0A%20%20%20%20%3CVALUE%20type%3D%22%5C%26quot%3BInteger%5C%26quot%3B%22%3E%0A%20%20%20%20%20%20%3CUSERID%3E%3C%2FUSERID%3E%0A%20%20%20%20%3C%2FVALUE%3E%0A%20%20%3C%2FEQ%3E%0A%3C%2FMEMBERSHIP%3E%3C%2FOR%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
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
Highlighted

@rautchetan27try to use the below format

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

@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>

Highlighted

@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>

Highlighted

@Sudharsan K 

 

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

How we can check for value

Highlighted

@Sudharsan K 

 

do I need to put <Where> tag?

 


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

Highlighted

@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>