CAML query to filter sharepoint list on the basis of Currentuser group


I am using following query to filter List items on the basis of current user group, so current user only can see list items which having value in column Vendor same as name of currentuser group.

I have <And> condition in query which working correctly, but Condition for Currentusergroup is not working and its not filtering with value of currentusergroup


<Where><And><Eq><FieldRef Name="ADM_x0020_ID"/><Value Type="Text">1234</Value></Eq><Eq><FieldRef Name="Vendor_new"/><Value Type="Text">IBM</Value></Eq></And><Eq><Membership Type="CurrentUserGroups"><FieldRef Name="Vendor"/></Membership></Eq></Where>


anyone can tell whats wrong in above query?

14 Replies

@rautchetan27 : I think you are not comparing Vendor value with the user, kindly check below query. Hope it will help. Try to use user ID instead of username query as below:

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


If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.




I dont want to use UseId, i am trying following query, but no Luck..any idea whats going wrong?


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



i tried following query also, but it throw error


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

@rautchetan27 Try something like below:

1)<Where><Contains><FieldRef Name=\"Vendor\" /><Value Type='Text'>" + currentUser + "</Value></Contains></Where>

Note: When you use text <contains> tag will give you the results all that is matching.
2) <Where><Eq><FieldRef Name=\"Vendor\" /><Value Type='User'>" + currentUser + "</Value></Eq></Where>
3) <Where><Eq><FieldRef Name='Vendor' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></Where>
Note: with User ID - it will give you the exact match and will return only one value. 
Hope it helps !





I dont want to use user,  in vendor column I will have sharepoint group names





I have three sharepoint groups with same Name and users are added to one of the sharepoint groups


so when user access list, it will able to see only list items having value on column same as user group name thats why i want to use



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


On internet i found same solution many places but somehow its not working for me


@rautchetan27 :  Ohk got you ! Yours query looks correct in that case.

1) First check whether you have access to check others task or not .

2) Second, if you are doing this programmatically then you can check you query via CAML Query Builder.

3) You can use CSOM to display the specific items as you want. Use SPWeb.CurrentUser.Groups to get the collection of groups of which the user is a member. And use CAML query to filter on items which were assigned to current user and current user’s groups.



I am getting error where using Membership tag


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


error Correlation ID: 076f579f-20f1-b000-c31a-67e814dcf994


Not sure whats wrong

@rautchetan27 : Hope "Vendor" column is a person/groups type column. I tried below query and it worked for me:

<Membership Type='CurrentUserGroups'>
<FieldRef Name='AssignedTo'/>



Thanks for reply, I changed column to Person/Groups and now I am not getting error


but in that person/group column when I try to edit, its not Populating sharepoint that active directory group that we need to populate in Person/group column?

is it possible to assigned sharepoint group?

Please help, I am new to sharepoint and struggeling this requirement

best response confirmed by rautchetan27 (Contributor)

@rautchetan27 : When you check person/groups column settings, you will find properties as per below screenshot


Allow selection : People and Groups should be selected

Choose from All users if you want to allow both people and groups or SharePoint Groups only to show SP groups.


Hope it helps !


If I have answered your question, please mark your post as solved.

if you like my response, please give it a thumbs up.



Many thanks for the help! it resolved my issue and its working for me..thanks again!!!

@rautchetan27 : Glad to hear that I am able to resolve your query. Thanks !

If I have answered your question, please mark your post as solved.

if you like my response, please give it a thumbs up.



Can we define different permissions for members of same group?


I have one group say "IT infra"

in that group I have 4 members, i want 3 members can have Read permission and one member only can have read/write/edit permission


is this possible?

@rautchetan27 : Group permission is applied to all the members of the group. Within group you cannot categorize the permission. This mentioned scenario you can handle through unique permission. But you have to include same members in different groups.