0

I'm trying to set the OnlyAllowMembersViewMembership property of all the sitegroup s on my site collection to FALSE programmatically. I can get the values with code below, but I'm not quite connecting the dots on how to set the values of the existing groups. How do I update that property? I understand the sitegroup collection has a property of set_onlyAllowMembersViewMembership but I don't know how to use it.

//global variables
var showHtml = ''; 
// define a ClientContext for the specified SP site    
 var ctx = SP.ClientContext.get_current();

// attach a onRequestFailed function to the client context.
ctx.add_requestFailed(function (sender, args) {
    alert('Request failed: ' + args.get_message());
});

function doWork() {
    //debugger;
    var groupCollection = ctx.get_web().get_siteGroups();
    ctx.load(groupCollection);
    ctx.executeQueryAsync(function () {
        var groupEnumerator = groupCollection.getEnumerator();
        var groupCount = 0;
        while (groupEnumerator.moveNext()) {
            var ogroup = groupEnumerator.get_current();
            var currGroup = ogroup.get_objectData().get_properties();
            console.log("Title:",currGroup.Title,"ID",currGroup.Id,"OnlyAllMembersViewMembership",currGroup.OnlyAllowMembersViewMembership);
            groupCount ++;
            showHtml += currGroup.Title + "; " + currGroup.Id +"; " + currGroup.OnlyAllowMembersViewMembership + "<br>";
        }
        $('#show').append("<b>Number of groups: " + groupCount + "</b><br><br>");
        $('#show').append(showHtml);
    });
};

window.onload = doWork;

1 Answer 1

0

Try the below code:

//global variables
var showHtml = ''; 
// define a ClientContext for the specified SP site    
 var ctx = SP.ClientContext.get_current();

// attach a onRequestFailed function to the client context.
ctx.add_requestFailed(function (sender, args) {
    alert('Request failed: ' + args.get_message());
});

function doWork() {
    //debugger;
    var groupCollection = ctx.get_web().get_siteGroups();
    ctx.load(groupCollection);
    ctx.executeQueryAsync(function () {
        var groupEnumerator = groupCollection.getEnumerator();
        var groupCount = 0;
        while (groupEnumerator.moveNext()) {
            var ogroup = groupEnumerator.get_current();     

            var currGroup = ogroup.get_objectData().get_properties();
            console.log("Title:",currGroup.Title,"ID",currGroup.Id,"OnlyAllMembersViewMembership",currGroup.OnlyAllowMembersViewMembership);
            groupCount ++;
            showHtml += currGroup.Title + "; " + currGroup.Id +"; " + currGroup.OnlyAllowMembersViewMembership + "<br>";

            //change OnlyAllowMembersViewMembership property
            ogroup.set_onlyAllowMembersViewMembership(false);
            ogroup.update();
            ctx.load(ogroup);
            ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
        }
        $('#show').append("<b>Number of groups: " + groupCount + "</b><br><br>");
        $('#show').append(showHtml);
    });
};

function onQuerySucceeded(){
    console.log("success");
}
function onQueryFailed(){
    console.log("error");
}

window.onload = doWork;
1
  • Glad to hear that ! Could you please mark it as answer ? Apr 11, 2017 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.