Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint 2013 get Group Owner Login Name and set Group Owner via JavaScript

$
0
0


I'm try to first find out an owner of a Group in SharePoint 2013, and then I would like to try and set the owner of a Group using JavaScript, I am will to try either JSOM, or REST API. (if I understand how that, JSOM vs. REST works)

 

I have tried with JSOM:

function getGroupOwner (desiredGroupName) {

   var clientContext = new SP.ClientContext.get_current();

   var web = clientContext.get_web();

   var groups = web.get_groups();

   var group = groups.getByName(desiredGroupName);

   var groupOwner = group.get_owner();

 

   clientContext.load(web);

   clientContext.executeQueryAsync( function() {

       console.log('Success');

       var ownerLoginName = groupOwner.get_loginName();

       console.log('ownerLoginName: ' + ownerLoginName);

   },

   function (sender, args) {

       console.log('Error: ' + args.get_message());

   }

}

 

I at least get a "Success", but it then gives me an error of:

 

The property or field 'LoginName' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

 

Once I solve this, I was going to move onto the set_owner() function.

 

Any advice on this would be appreciated.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>