SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a way I can use the below with something like getByName(thisGroup), instead of getById(10) in SP 2010 jsom:

function setSomeUsers(dataObj, projGroup) {
    var clientContext = new SP.ClientContext.get_current();
    var collGroup = clientContext.get_web().get_siteGroups();
    //instead of this:
    var oGroup = collGroup.getById(10);
    // something like the below
    // var oGroup = collGroup.getByName(projGroup);
    var userCreationInfo = new SP.UserCreationInformation();
    this.oUser = oGroup.get_users().add(userCreationInfo);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onSetAdminsQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));


function onSetAdminsQuerySucceeded() {   
    alert(this.oUser.get_title() + " added.");

// plus the failed here

so if the above isn't possible, is there a way to get the name and id out of get_sitegroups() callback?

appreciated as always!

share|improve this question
up vote 14 down vote accepted

AFAIK, it's only possible to use getByName in SharePoint 2013, not in 2010. See MSDN reference for more information

 var groupCollection = clientContext.get_web().get_siteGroups();
 visitorsGroup = groupCollection.getByName("SomaGroupName");
share|improve this answer
thanks Falak. yeah I believe you are correct. so I see what I think is the proper way to get there, another get for the groups in the site and loop through the callback comparing the name, then get the id of the right group and fire this. appreciated! – Justin Jul 21 '13 at 11:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.