Skip to content

Instantly share code, notes, and snippets.

@sksnips
Created September 25, 2016 05:21
Show Gist options
  • Save sksnips/79eee97a934f3094ee1c591e99c6a8e7 to your computer and use it in GitHub Desktop.
Save sksnips/79eee97a934f3094ee1c591e99c6a8e7 to your computer and use it in GitHub Desktop.
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