Set Site Group Owner in SharePoint using JSOM

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

  • function SetSiteGroupOwner() {
  •     // 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();
  •  
  •     // Option 1: Set a User as an owner
  •     var ownerUser = clientContext.get_web().ensureUser("Logon Name");
  •  
  •     // Option 2: Set Group as an owner  
  •     var ownerGroup = clientContext.get_web().get_siteGroups().getByName("test Visitors");
  •  
  •     // Specify the group name over here. This is the group of which "owner" needs to set
  •     var oGroup = clientContext.get_web().get_siteGroups().getByName("New Group");
  •  
  •     // Set the owner property of the group
  •     // You can either specify "User" from Option 1 or "Group" from Option 2
  •     oGroup.set_owner(ownerGroup);
  •  
  •     // Update Group
  •     oGroup.update();
  •  
  •     // 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