Check if user belongs to SharePoint group

In SharePoint, we need not allow all the users to see all the controls in the form. We may need to show, hide or disable the SharePoint controls for users in particular SharePoint group. Lets see this as two parts.

  • Check if logged in user belongs to SharePoint group(in SharePoint 2010, 2013)
  • Show/Hide/Disable fields using sputility.js

PART 1: Check if logged in user belongs to SharePoint group

  • Create a SharePoint group with the desired permissions and add users to it.
  • When we go to the address bar, we can see the url of SharePoint group as ../_layouts/people.aspx?MembershipGroupId=7
  • ID in the above url is 7. Use this ID for groupCollection.getById(ID) in SharePoint 2010 and use the groupname in sharepoint 2013

SharePoint 2010

ExecuteOrDelayUntilScriptLoaded(IsUserExists, "sp.js");
var group;
var users;
var ctx;
var groupCollection;
var user;
var currentuser;
function IsUserExists()
ctx = SP.ClientContext.get_current();
groupCollection = ctx.get_web().get_siteGroups();
group = groupCollection.getById(7);
ctx.executeQueryAsync(Function.createDelegate(this, this.OnGetGroupSuccess), Function.createDelegate(this, OnFailure));
function OnGetGroupSuccess()
ctx.executeQueryAsync(Function.createDelegate(this, this.OnGetuserSuccess), Function.createDelegate(this, OnFailure));
function OnGetuserSuccess()
var userEnumerator = users.getEnumerator();
while (userEnumerator.moveNext())
var user = userEnumerator.get_current();
if (user.get_id() == currentuser.get_id())
alert("You have access to this form");
//sputility code to show the controls
function OnFailure(sender, args) {
alert("You do not have Permission");
//sputility code to hide/disable the controls

SharePoint 2013:

ExecuteOrDelayUntilScriptLoaded(IsCurrentUserHasContribPerms, 'SP.js');
function IsCurrentUserHasContribPerms()
IsCurrentUserMemberOfGroup("Owners", function (isCurrentUserInGroup) {
// sputility code to show the controls
//sputility code to hide/disable the controls
function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
var currentContext = new SP.ClientContext.get_current();
var currentWeb = currentContext.get_web();
var currentUser = currentContext.get_web().get_currentUser();
var allGroups = currentWeb.get_siteGroups();
var group = allGroups.getByName(groupName);
var groupUsers = group.get_users();
function OnSuccess(sender, args) {
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == currentUser.get_id()) {
userInGroup = true;
function OnFailure(sender, args) {

We will see Part 2 in next article.

If my post is helpful to you, please like my article and post your valuable feedback or query in comments.


Leave a Comment

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

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s