Saturday, December 29, 2012

How to identify if user is in a particular permission group using Web Service

Some days back I was faced with a task of changing the behavior of the list new /Edit form based on the user presence in a particular permission group.

Problem Statement: If the user was present in “Members” group I need to hide some fields and if he was present in the “Owners” Group, I need to show all those fields.

Solution: By calling the GetGroupCollectionFromUser operation of the Users and Groups Web Service, you can determine whether your user is in the group. I got this from Marc post.

The only small issue fixed in that post code was that it worked not on every browser, hence I need to modify it a little to support cross browser. I used responseText instead of responseXML.

  1. First we need to add JavaScript directives to the page, I have provided the CDN link which you can directly use or can download the libraries to use it.
  3. Then include the below script to check the current logged user’s group

    These scripts can be used on CEWP to achieve the desired result.


  1. SPServices is unnecessary and outdated. The best practice is to use CSOM.

  2. Nice one. SPServices are really powerful. Lot of reusable stuff it has.

  3. Here's a general place to look for using the CSOM and a couple of the main objects to look at using when performing this using the CSOM.

    // site context basically SPContext for CSOM

    // Gets the web site groups, returns GroupCollection object

    // Get the current user

    // Get list of users from a group