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

Posted: September 26, 2014 in SharePoint2013


In Share Point we have If condition “If this user is member of this share point group”
We can use this condition to check any user belongs to particular group or not.


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




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  forms on Custom List.

Step 1: Navigate to your SharePoint 2013 site.

Step 2: From this page select Site Actions | Edit Page:

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”.

Step 3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link; click it. You can insert the HTML and/or JavaScript as in the following:


<script src=”/sites/JS/jquery-1.4.2.min.js”></script>

<script type=”text/javascript”>

ExecuteOrDelayUntilScriptLoaded(disableControls, “sp.js”);


var clientContext = null;

var web = null;

var users ;

var oList;

var oListNew;


function disableControls()


clientContext = new SP.ClientContext();

var groupCollection = clientContext.get_web().get_siteGroups();

var group = groupCollection.getById(4);//the SharePoint usergroup

users = group.get_users();



currentUser = clientContext.get_web().get_currentUser();



this.onQuerySucceeded), Function.createDelegate(this,




function onQuerySucceeded()


if(this.users.get_count() >0)


var 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 onQueryFailed(sender, args)






Final Result:



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