1

I want get list group member of sites and email of users of groups from my addins:

enter image description here

I had tried this code but, it can't: it showing error testsite Members is not exist

function loadcboGroupofSite() {
    var hostWebContext = new SP.AppContextSite(clientContext, hostWebURL);
    var listStatus = hostWebContext.get_web().get_lists().getByTitle('testsite Members');
    var camlQuery = new SP.CamlQuery();
    var Items = listStatus.getItems(camlQuery);
    clientContext.load(Items, 'Include(Title, Id)');
    clientContext.executeQueryAsync(Function.createDelegate(this, function (data) {
        var listItemInfo = "<option>All</option>";
        // Iterate through Enumerator
        var oEnumerator = Items.getEnumerator();

        while (oEnumerator.moveNext()) {
            
         
            var title = oEnumerator.get_current().get_item('Title');       
          
            listItemInfo += '<option>' + title + '</option>';          
        }
    
        $("#cboGroup").html(listItemInfo);

    }), Function.createDelegate(this, function (sender, args) {
        alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

    }));
}

How can get list Members of web host from addins?

1

Your code hostWebContext.get_web().get_lists().getByTitle('testsite Members'); is to get a list instead of get a group. To get a group in the web, you need to use SP.Web.siteGroups property.

Change your code to the following:

var group = hostWebContext.get_web().get_siteGroups().getByName('testsite Members');
var users = group.get_users();
clientContext.load(users);
clientContext.executeQueryAsync(Function.createDelegate(this, function (data) {
    var listItemInfo = "<option>All</option>";
    // Iterate through Enumerator
    var oEnumerator = users.getEnumerator();

    while (oEnumerator.moveNext()) {


        var title = oEnumerator.get_current().get_title();
        console.log(title);
        listItemInfo += '<option>' + title + '</option>';
    }
2
  • thank you very much.
    – D T
    Jan 18 at 8:05
  • You are welcome :) Jan 18 at 8:11

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.