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.