Create groups

var arrayGroups = [{ name:"gr1", desc: "" },
 { name: "gr2", desc: "" },

]

var syncGroup = new Synchronizer(Phase_CreateGroups);


function CreateGroups()
{
 //Get all groups in site
 var groupCollection = web.get_siteGroups();

context.load(groupCollection);

arrayGroups.forEach(function (item) {
 // Create Group information for Group
 var membersGRP = new SP.GroupCreationInformation();
 membersGRP.set_title(item.name);
 membersGRP.set_description(item.desc);

var oGroup = groupCollection.add(membersGRP);
 oGroup.set_onlyAllowMembersViewMembership(false);
 oGroup.update();
 context.load(oGroup);
 syncGroup.Send();
 context.executeQueryAsync(function () {
 syncGroup.Get();
 SuccessMessage('Group <strong>' + item.name + '</strong> was created');

}, function (sender, args) {
 syncGroup.Get();
 AlerMessage('Group <strong>' + item.name + '</strong> already exist');
 
 });

});


}
Advertisements
This entry was posted in JSOM, sharepoint online. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s