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.


Rename New Item link in SharePoint 2013

Let us see how to rename “New Item” link in SharePoint 2013 to custom text with respect to SharePoint list name. Say,  For example: If there is a Project list, we need to rename New Item to Add new Project. In such cases, you can follow the below steps:

  • Go to the desired page and edit it
  • Add a Script editor Web Part available under Media and Content Category
  • Copy and paste the below in the script editor web part.
<script src="../Scripts/jquery.min.js"></script>
function ChangeText()
document.getElementById("idHomePageNewItem").getElementsByTagName("span")[1].innerHTML="Add New Project";

Please do not forget to like or rate this article 😛