1

Does anyone have an example of displaying members of the Site Owners group on a SharePoint Page using CSOM? I'd like to have this show like a web part for each Site in SharePoint 2013.

0

Out of the box

You can use out of the box Site Users Web Part.

Add this web part and edit properties, then choose Show People In The Group and set the group you want to display.

Custom Code

var siteUrl = '/sites/MySiteCollection ';

function retrieveAllUsersInGroup() {
    var clientContext = new SP.ClientContext(siteUrl);
    var collGroup = clientContext.get_web().get_siteGroups();
    var oGroup = collGroup.getById(7);
    this.collUser = oGroup.get_users();
    clientContext.load(collUser);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
    var userInfo = '';
    var userEnumerator = collUser.getEnumerator();
    while (userEnumerator.moveNext()) {
        var oUser = userEnumerator.get_current();
        this.userInfo += '\nUser: ' + oUser.get_title() + 
            '\nID: ' + oUser.get_id() + 
            '\nEmail: ' + oUser.get_email() + 
            '\nLogin Name: ' + oUser.get_loginName();
    }
    alert(userInfo);
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

https://msdn.microsoft.com/en-us/library/office/hh185012(v=office.14).aspx

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.