10

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();
    userCreationInfo.set_email(dataObj.userEmail);
    userCreationInfo.set_loginName(dataObj.userLogin);
    userCreationInfo.set_title(dataObj.userTitle);
    this.oUser = oGroup.get_users().add(userCreationInfo);
    clientContext.load(oUser);
    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!

1 Answer 1

14

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");
1
  • 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, 2013 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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