1

I'm writing a SharePoint hosted app that allows the user to create groups and assign users to them. However, every time I run the code, it gives me a Permission Denied message, saying I don't have the permissions to add the group. I've given the app FullControl Web permissions in the manifest, and the same app is able to add files, lists, etc without any problems. Here's the code for the method which adds the group:

/*groupName is a string and usersToAdd is an array of SP.User*/
function createGroup(groupName, usersToAdd) {
    var clientContext = SP.ClientContext.get_current();
    var website = clientContext.get_website();

    var groupInfo = new SP.GroupCreationInformation();
    groupInfo.set_title(groupName);

    var newGroup = website.get_siteGroups().add(groupInfo);
    usersToAdd.forEach(function(user) => { newGroup.get_users().addUser(user); });

    var readerRole = website.get_roleDefinitions().getByType(SP.RoleType.reader);
    var roleDefBinding = new SP.RoleDefinitionBindingCollection(clientContext);
    website.get_roleAssignments().add(newGroup, roleDefBinding);

    clientContext.executeQueryAsync();
}

I've only been working with SharePoint for about a month, so there's plenty I still don't understand about it. Can someone give me an idea about how to give the app the permissions it needs?

1
  • Off the top of my head, it's Site collection permissions that you need to create the group. Commented Jun 16, 2015 at 6:35

1 Answer 1

0

Off the top of my head, it's Site collection permissions that you need to create the group.

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.