Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code snippets helps to create a new group in SharePoint site collection using PnP JS library
//Author: Shantha Kumar T
//Supports: SharePoint Online, SharePoint 2013+
//PnP JavaScript file available from https://github.com/OfficeDev/PnP-JS-Core
//More details: http://www.ktskumar.com/2016/09/pnp-js-core-create-sharepoint-group
<script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>
<script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script>
<script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>
<div id="sample"></div>
<script type="text/javascript">
//The below PnP property used to create a new SharePoint Group
$pnp.sp.web.siteGroups.add({
Title: "Group Name"
}).then(function(result) {
var grpInfo = "";
var grp = result.data;
grpInfo += "SharePoint Group '<strong>" + grp.Title + "</strong>' created successfully!<br/>";
grpInfo += "Below are some of the newly created group properties,<br/>";
grpInfo += "Description :" + grp.Description; + "<br/>";
grpInfo += "AllowMembersEditMembership: " + grp.AllowMembersEditMembership + "<br/>";
grpInfo += "OnlyAllowMembersViewMembership: " + grp.OnlyAllowMembersViewMembership + "<br/>";
grpInfo += "AllowRequestToJoinLeave: " + grp.AllowRequestToJoinLeave + "<br/>";
grpInfo += "AutoAcceptRequestToJoinLeave: " + grp.AutoAcceptRequestToJoinLeave + "<br/>";
grpInfo += "RequestToJoinLeaveEmailSetting: " + grp.RequestToJoinLeaveEmailSetting + "<br/>";
document.getElementById("sample").innerHTML = grpInfo
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.