.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Client Object Model to Determine Whether a User Belongs to a Group and Hide Controls in New/Edit For

Posted By:Sagar Pardeshi       Posted Date: October 07, 2014    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article you will learn about the Client Object Model to determine whether a user belongs to a group and hide controls in new and edit forms.


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:

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend