Delete Site Group in SharePoint using JSOM

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

  • var oGroupCollection, clientContext, oGroup;
  • function DeleteSiteGroup() {
  •     // 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();
  •  
  •     // Get Site Group Collection object
  •     oGroupCollection = clientContext.get_web().get_siteGroups();
  •  
  •     // Get the Site Group
  •     oGroup = clientContext.get_web().get_siteGroups().getByName("New Group");
  •  
  •     // Load Site groups and Group object
  •     clientContext.load(oGroupCollection);
  •     clientContext.load(oGroup);
  •  
  •     // Execute the query to the server.
  •     clientContext.executeQueryAsync(onsuccess, onfailed);
  • }
  •  
  • function onsuccess() {
  •  
  •     //Remove the group from the collection
  •     oGroupCollection.removeByLoginName(oGroup.get_loginName());
  •  
  •     //Execute the batch
  •     clientContext.executeQueryAsync(FinalQuerySuccess, FinalQueryFailure);
  • }
  •  
  • function onfailed(sender, args) {
  •     console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
  • }
  •  
  • function FinalQuerySuccess(sender, args) {
  •     console.log('Success');
  • }
  •  
  • function FinalQueryFailure(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