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() ? Jul 19, 2014 at 14:17

1 Answer 1


Remove this keyword from this.userInfo.

  • Can you please provide more details.
    – Asad Refai
    Apr 20, 2016 at 5:33

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.