我设法创建组并设置正确的角色,但是我无法让访问者,成员和所有者的同事来工作,我不知道使用什么代码以及在哪里使用,这是到目前为止的代码:
for(var i = 0; i < GroupInfo.length; i++) {
var siteUrl = url + projektinfo.Sitecollection + "/" + projektinfo.Projektnummer;
var currentCTX= new SP.ClientContext(siteUrl);
var currentWEB = currentCTX.get_web();
//Get all groups in site
var groupCollection = currentWEB.get_siteGroups();
// Create Group information for a Group
var membersGRP = new SP.GroupCreationInformation();
membersGRP.set_title(GroupInfo[i].GroupName + projektinfo.Projektnamn);
//membersGRP.set_description('');
//add group
oMembersGRP = currentWEB.get_siteGroups().add(membersGRP);
//Get Role Definition by name (http://msdn.microsoft.com/en-us/library/jj246687.aspx)
//return SP.RoleDefinition object
var rdContribute = currentWEB.get_roleDefinitions().getByName(GroupInfo[i].RoleName);
//Create a new RoleDefinitionBindingCollection.
var collContribute = SP.RoleDefinitionBindingCollection.newObject(currentCTX);
// Add the role to the collection.
collContribute.add(rdContribute);
// Get the RoleAssignmentCollection for the target web.
var assignments = currentWEB.get_roleAssignments();
// assign the group to the new RoleDefinitionBindingCollection.
var roleAssignmentContribute = assignments.add(oMembersGRP, collContribute);
counterRole = counterRole +1;
currentCTX.load(oMembersGRP);
currentCTX.executeQueryAsync(QuerySuccess(counterRole), QueryFailure);
}