Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 7 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

groupCollection.getByName("SomaGroupName")

this getByName method is not available in C#. please tell me the way to retrieve group by using GroupName in Client Objet Model in C#

share|improve this answer

Your Answer

 
discard

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.