Share via


SP.RoleDefinitionCollection Class

Applies to: SharePoint Foundation 2010

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

SP.RoleDefinitionCollection

Inherits

SP.ClientObjectCollection Class

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>

See Also

Reference

SP.RoleDefinitionCollection Methods

SP.RoleDefinitionCollection Properties

SP Namespace