Client Object Model to Check user belongs to a Group and Hide controls in New/Edit/Display Forms

Problem: Check user belongs to a SharePoint Group and Hide some controls in New/Edit/Display Forms on SharePoint  Custom List

The above problem can be solved with the below link only if you use infopath in document or form library

If you are using SharePoint list, you have to use the below steps to meet this requirement


The following Script which will help you in checking if the current logged in SharePoint user belongs to a SharePoint user group and based on it hide some controls in New/Edit/Display aspx forms on Custom List.

ExecuteOrDelayUntilScriptLoaded(hideControls, “sp.js”);

function hideControls()
clientContext = new SP.ClientContext();
groupCollection = clientContext.get_web().get_siteGroups();
group = groupCollection.getById(10); //The ID of the SharePoint user group
users = group.get_users();
currentUser = clientContext.get_web().get_currentUser();
this.onOperationSucceeded), Function.createDelegate(this,

function onOperationSucceeded()
if(users.get_count() >0)
UserExistInGroup = false;
for(var i=0; i < users.get_count(); i++)
if(users.itemAt(i).get_loginName() == this.currentUser.get_loginName())
UserExistInGroup = true;

if (UserExistInGroup)


function onOperationFailed(sender, args)

Thank you Anil for your contribution to fix this issue

About Joseph Velliah
As a SharePoint Evangelist my professional interests tend to be technical and SharePoint focused. I run a blog at "SP RIDER" where you can expect to read HOW TOs and scenarios that I run into during my day to day job. I hope my posts will give back a little to the community that is helped me.

One Response to Client Object Model to Check user belongs to a Group and Hide controls in New/Edit/Display Forms

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

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

%d bloggers like this: