1

How to get group object from group name something like this.

var groupCollection = clientContext.get_web().get_siteGroups();
group = groupCollection.getByName("Group Name");

Above code will work in SP2013. But not in SP2010.

1 Answer 1

3

You could do something like this:

var groupCollection = clientContext.get_web().get_siteGroups();
var myGroupName = "Group Name";
var myGroup = null;

clientContext.load(groupCollection);
clientContext.executeQueryAsync(function(){
        var groupEnumerator = groupCollection.getEnumerator();
        while(groupEnumerator.moveNext()){
            var currentGroup = groupEnumerator.get_current();
            if (currentGroup.get_title() == myGroupName)
            {
                myGroup = currentGroup;
                break;
            }
        }
    },
    function(sender,args){
        console.log(args.get_message());
    }
);

After this code runs, you should have the details of your group in the myGroup variable.

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.