Create Site Group in SharePoint using JSOM

The example in this topic show how to use JSOM to Create Site Group in SharePoint

  • function CreateSiteGroup() {
  •     // 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");
  •     clientContext = new SP.ClientContext();
  •  
  •     // NOTE: The user who is running the code will be added as "Group Owner"
  •     var oGroupCollection = clientContext.get_web().get_siteGroups();
  •  
  •     // GroupCreationInformation object
  •     var oGroupCreationInformation = new SP.GroupCreationInformation();
  •  
  •     oGroupCreationInformation.set_title("New Group");
  •     oGroupCreationInformation.set_description("New Group Description");
  •  
  •     var oGroup = oGroupCollection.add(oGroupCreationInformation);
  •  
  •     // Execute the query to the server.
  •     clientContext.executeQueryAsync(onsuccess, onfailed);
  • }
  •  
  • function onsuccess() {
  •     console.log('Success');
  • }
  •  
  • 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


© 2019 Code SharePoint