Provision SharePoint Site using Custom Template with PnP JS

Ahamed Fazil Buhari
 
Senior Developer
September 27, 2018
 
Rate this article
 
Views
3876

Hi,

In this article we will see how to provision SharePoint site using PnP JS and more we can provision by our own custom site template. For this we need to know the GUID of your custom template, there are various way to get GUID of site template and one of the easy way is shown below,

I just moved to the page where we can manually create subsite (https://<sharepointURL>/_layouts/15/newsbweb.aspx ). Right click on the custom template name and select Inspect from your browser so that you can see the source of the page and from that we can get GUID of your custom template.

 

image

Once we get the template ID, we need to call below PnP code to provison site and in the parameter we need to provide values for following options –

Site Title, URL, description, template name or ID, lang, permission Inheritance.

 import pnp from "sp-pnp-js/lib/pnp";
 
 pnp.sp.web.webs
         .add(
           "New Sub Site",
           "newsite",
           "Description for the new Site",
           "{1BDB855A-CC85-4AF4-8C58-BCDD7F02xxxx}",
           1033,
           true
         )
         .then(function(result) {
           if (result.data.Created) {
             alert("Site created successfully");
           }
         })
         .catch(e => {
           console.log("eeerrr", e);
         });
 

 

 

image

Happy Coding

Ahamed

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint, Azure, M365, SPFx, .NET and client side scripting - JavaScript, TypeScript, ...read more
 

Leave a comment