Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code snippet used to create a new group with different parameters in SharePoint Site Collection using PnP JavaScript 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 2",
Description: "My description for the new group",
AllowRequestToJoinLeave: true,
AutoAcceptRequestToJoinLeave: true,
RequestToJoinLeaveEmailSetting: "myname@email.com",
AllowMembersEditMembership: true,
}).then(function(result) {
samgrp = result.data;
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>
@vochitan90

This comment has been minimized.

Copy link

@vochitan90 vochitan90 commented Aug 5, 2020

It always by default who create the group and not possible to update the group owner. How to update group owner?
I know we have "owner" parameter but I don't know how to use it. Please advice, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment