Using SPServices “GetGroupCollectionFromUser” operation

SharePoint 2010 Used

We had a task in which we had to show and hide items on a page based on which group a user belonged to.
We needed a way to identify if the current user belonged to a specific group. We were able to accomplish this using the “GetGroupCollectionFromUser” operation of SPServices.
Lets say you had a site with many groups but 5 of them were “Finance”. To identify “Finance”, it was appended with “_FIN”.

Using “GetGroupCollectionFromUser” operation, here’s the function that was created.

A function DecideGroup(url) with one parameter called ‘url’ was created.

see below:

function DecideGroup(url)
var url = siteUrl+"/";
var isFIN;
var bsoGrpName=null;
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
webURL: url,
completefunc: function(xData, Status) {
$(xData.responseXML).find("Group[Name$='_FIN']").each(function() { //find any group ending in '_FIN'
finGrpName = $(this).attr("Name");
return false; //Once you find they are in a finance group, no need to go continue with the loop

return finGrpName; //return group name

jQuery and SP Services SharePoint SharePoint 2010

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: