Get All the Roles in SharePoint using JSOM

The example in this topic show how to use JSOM to Get All the Roles in SharePoint

  • var oRoleDefinitions;
  • function GetAllRoleDefinitions() {
  •     // You can optionally specify the Site URL here to get the context
  •     // If you don't specify the URL, the method will get the context of the current site
  •     // var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");
  •     var clientContext = new SP.ClientContext();
  •  
  •     //Get role definitions object
  •     oRoleDefinitions = clientContext.get_web().get_roleDefinitions();
  •  
  •     // Load group users
  •     clientContext.load(oRoleDefinitions);
  •  
  •     // Execute the query to the server.
  •     clientContext.executeQueryAsync(onsuccess, onfailed);
  • }
  •  
  • function onsuccess() {
  •  
  •     var oEnumerator = oRoleDefinitions.getEnumerator();
  •  
  •     while (oEnumerator.moveNext()) {
  •         var oRoleDefinition = oEnumerator.get_current();
  •         console.log("Role Definition name: " + oRoleDefinition.get_name());
  •     }
  • }
  •  
  • function onfailed(sender, args) {
  •     console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
  • }

Thank you for reading this article. This code was tested in SharePoint 2013

We value your feedback:

Page URL:

Name:

 

Email:

 
 

Feedback:

 

© 2019 Code SharePoint