I am trying to get all the Users from a SharePoint Owner's Group for a subsite. Below Script is Working fine . But it displays both Site and Subsite Users of Owner's Group.

For example If SITE A has SITEOWNERS GROUP and it has SUBSITE A1 . Now when i use this Script in sub site, It should Display the users from SUBSITEOWNERS GROUP. Howeever it Displays users from Both SITEOWNERS GROUP & SUBSITEOWNERS GROUP. Can any one Help me on this to correct my Code.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js "></script>
<script type="text/javascript" src="http://test.com/Style%20Library/JAVASCRIPT/jquery.SPServices-2014.02.min.js"></script>
<div id='tblMain' style="float:left">
 <table id="myUsersTable"  border="1" cellpadding="2" width="400px">

<script type="text/javascript">
$(document).ready(function() { 
var currentcontext = null; 
var currentweb = null; 
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', GetGroups);

function GetGroups() 
currentcontext = new SP.ClientContext.get_current(); 

currentweb = currentcontext.get_web(); 

this.groupCollection = currentweb.get_siteGroups(); 


currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess), 
Function.createDelegate(this, this.ExecuteOnFailure)); 
function ExecuteOnSuccess(sender, args) 
var listEnumerator = this.groupCollection.getEnumerator(); 
while (listEnumerator.moveNext()) 
var item = listEnumerator.get_current(); 
groupName = item.get_title(); 
    if (groupName.toLowerCase().indexOf("owners") >= 0)

function ExecuteOnFailure(sender, args) 

function GetData(groupName)
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getbyname('" + groupName +"')/users",
        type: "GET",
        dataType: "json",
        headers: {
        Accept: "application/json;odata=verbose", 
          success: getUsersFromGroupSuccessHandler,
          error: getUsersFromGroupErrorHandler
function getUsersFromGroupSuccessHandler(data) 
         checkUsers = data.d.results.length;
         var Owners = [];

        if (checkUsers == 0) 

            alert ("There are no results for this");
            $.each(data.d.results, function(index, item)
                var OwnerName = item.Title;
                var OwnerEmail= item.Email;





function AddRowToTable(OwnerName,OwnerEmail)

                            "<td >" + OwnerName + "</td>" +
                            "<td>" + OwnerEmail + "</td>"+

function getUsersFromGroupErrorHandler(data, errorCode, errorMessage)
alert("Could not get users from group: " + errorMessage);

  • You are doing a lazy match on the owner group, if (groupName.toLowerCase().indexOf("owners") >= 0), the more subsite you have, the more will appear. You need to be more explicit in the group you are looking for. Commented Apr 16, 2015 at 16:50

1 Answer 1


You are getting site collection groups earlier you are retrieving groups from the site collection, but when you execute your GetData() function, you are passing in a group name, but executing it at the root level.


instead of


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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