0

I have root site and it has many subsites. I have to get Site owners of each subsite using CMOS. I have writtern below code but its not giving owner's detials instead its giving all site group information.

 var ctx = new SP.ClientContext("<subsite url>");
        var web = ctx.get_web();
        var groupCollection = web.get_siteGroups();
        ctx.load(groupCollection, 'Include(Users,Title)');

Now, Once I get values in "groupCollection", I am looping into groups and then users. But I am getting all sharepoint group not specific to .

Please suggest where I am wrong.

0

You can make use of the get_associatedOwnerGroup() method to get the owner group members.

Modify your code from below sample:

var clientContext = new SP.ClientContext("<subsite url>");
var oGroup = clientContext.get_web().get_associatedOwnerGroup();
var collUser = oGroup.get_users();
clientContext.load(collUser);

clientContext.executeQueryAsync(function(){

    var userEnumerator = collUser.getEnumerator();
    while (userEnumerator.moveNext()) {
        var oUser = userEnumerator.get_current();
        //do stuff with user object
        console.log(oUser.get_email());

    }},function(){
        console.log("error");
});
  • Thanks for reply. But its giving me Root site owners emails not <subsite url> owners email. – Prashant K Mar 24 '18 at 7:18

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.