Determining if a User Is in a Permission Group with SharePoint’s Web Services

It’s not unusual to want to know if a user is in a certain permission group and change how a page behaves based on whether or not s/he is.  AlexLee over on EndUserSharePoint.com‘s Stump the Panel asked how you might be able to do this using SharePoint’s Web ServicesjQuery Library for SharePoint Web Services (SPServices) to the rescue!

By calling the GetGroupCollectionFromUser operation of the Users and Groups Web Service, you can determine whether your user is in the group.  Here’s the example code from Alex’s post (altered a little bit for simplicity):

$(document).ready(function() {

   $().SPServices({
     operation: "GetGroupCollectionFromUser",
     userLoginName: $().SPServices.SPGetCurrentUser(),
     async: false,
     completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='GroupNameHere']").length == 1)
        {
           ... do something ...
        }
      }
   });
});

Remember that this jQuery call will occur on the client side, so it’s not a good method to use if you’re trying to enforce permissions. However, it can allow you to alter the page on the fly based on the user’s group membership.

Similar Posts

79 Comments

  1. Thank You much Marc! Works like a charm! :)

    >>However, it can allow you to alter the page on the fly based on the user’s group membership.
    – used exactly for it.

    Best regards,
    Gennady

Leave a Reply

Your email address will not be published. Required fields are marked *

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