I need to read the members of a SharePoint group created in my main site from a subsite with exclusive (non-inherited) permissions, but without having to grant read permissions to the main site.

Thanks in advance

  • You want to give permissions to a certain group only on a subsite? Your question is a little bit confusing. – ranbo Feb 8 '17 at 16:39

You should be able to yes, so long as you set the group visibility to Everyone and make sure the users have browse directory and enumerate permissions privileges. Then you'd use code like this to check the membership:

function IsCurrentUserMemberOfGroup(groupName) {
        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;
                //do something
                    //do something else

        function OnFailure(sender, args) {

function processForm(){
    IsCurrentUserMemberOfGroup("Your Group");

ExecuteOrDelayUntilScriptLoaded(processForm, "sp.js");

Don't recall where I got this code, I believe it was from Vadim somewhere.

  • Thanks Erik, It worked! I had a code similar to yours, the problem was my context, I changed it by showing in your second line code: SP.ClientContext.get_current(); – mslash Feb 24 '17 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.