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

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

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 )

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.