SP.RoleDefinitionCollection object

Represents the collection of SP.RoleDefinition objects that define the role definitions that are available for use within the Web site.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.RoleDefinitionCollection()

Members

The RoleDefinitionCollection object has the following members.

Constructor

The RoleDefinitionCollection object has the following constructor.

Constructor

Description

RoleDefinitionCollection

This member is reserved for internal use and is not intended to be used directly from your code.

Methods

The RoleDefinitionCollection object has the following methods.

Method

Description

add

Adds a new role definition to the collection based on the role definition information.

getById

Gets the role definition with the specified ID from the collection.

getByName

Gets the role definition with the specified name.

getByType

Gets the role definition with the specified role type.

itemAt

Gets the role definition at the specified index in the collection.

Properties

The RoleDefinitionCollection object has the following properties.

Property

Description

childItemType

item

Gets the role definition at the specified index in the collection.

Example

The following example creates an input button on an application page that defines a new role and adds it to the role definitions collection.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    var roleDefinitionCollection;
    var roleDefinition;
    function runCode() {
        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();

            var permissionsManage = new SP.BasePermissions();
            permissionsManage.set(SP.PermissionKind.manageUsers);

            // Specify properties of the role definition.
            var roleCreationInfo = new SP.RoleDefinitionCreationInformation();
            roleCreationInfo.set_basePermissions(permissionsManage);
            roleCreationInfo.set_description('Role for managing user permissions.');
            roleCreationInfo.set_name('Manage User');
            roleCreationInfo.set_order(1);

            // Add to the role definitions collection.
            this.roleDefinitionCollection = web.get_roleDefinitions();
            this.roleDefinition = this.roleDefinitionCollection.add(roleCreationInfo);

            clientContext.load(roleDefinition);

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {
        alert('Created role: ' + this.roleDefinition.get_name());
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

REST resource endpoint

See RoleDefinitionCollection resource for more information.

Endpoint URI structure

http://<sitecollection>/<site>/_api/web/roledefinitions

HTTP requests

This resource supports the following HTTP commands:

GET syntax

GET http://<sitecollection>/<site>/_api/web/roledefinitions

POST syntax

POST http://<sitecollection>/<site>/_api/web/roledefinitions