having trouble getting users return from specified group using javascript per this on MSDN

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.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();


function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

i only modified it slightly on dev machine just to get started but I get collUser is undefined in the successful callback no matter what i try.....

tried replacing SP.ClientContext(siteUrl) with .get_current() as this is pretty much what i always do.

the site is a subsite that disinherits from the parent....does this have anything to do with it...i don't see that mentioned in the article (http://msdn.microsoft.com/en-us/library/hh185012(v=office.14).aspx)

thanks as always for any help; probably something simple i am missing but ??

  • If collUser is undefined it should not have anything to do with inherits or not, and the group exists I guess, else you would end up in the failed function. Have you tried referencing it with this.collUser.getEnumerator() ? – Anders Aune Jul 19 '14 at 14:17

Remove this keyword from this.userInfo.

| improve this answer | |
  • Can you please provide more details. – Asad Refai Apr 20 '16 at 5:33

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.