How To Create A Site Design And Site Script For SharePoint Online Modern Team Site

Introduction

 
In this article, you will see how to create a site design and site script for SharePoint Online Modern Team site. In each organization, there might be a requirement where when a new site is created custom branding, custom list or columns or site columns need to be created as soon as the site has been provisioned. In order to automate this process, Microsoft has introduced Site Design and site script where custom configurations can be applied while provisioning the site.
 
Site design is basically a template which will be selected while creating the site and it takes care of executing the custom configurations (actions) mentioned in the site scripts. Site Design can be applied to even existing templates which are available by default.
 
Site scripts are JSON file which contains the ordered list of actions that need to be executed. Latest Schema can be referred from this location.
 
Site designs can be created and registered to group connect modern Team site and communication site and group less team site. This can also be applied to an existing site collection.
 
In this article, you will see how to create a site design which creates a custom list including few fields.
 

Create a site script

 
Open Notepad and copy the below JSON. Save the file as site-script.json. This JSON contains the action to create a list and adding fields to the list. Refer to this schema for more information.
  1. {  
  2.     "$schema""https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",  
  3.     "actions": [  
  4.         {  
  5.             "verb""createSPList",  
  6.             "listName""VJ Custom List",  
  7.             "templateType": 100,  
  8.             "subactions": [  
  9.                 {  
  10.                     "verb""SetDescription",  
  11.                     "description""VJ Custom List created through Site Design"  
  12.                 },  
  13.                 {  
  14.                     "verb""addSPField",  
  15.                     "fieldType""Text",  
  16.                     "displayName""Text Column",  
  17.                     "isRequired"false,  
  18.                     "addToDefaultView"true  
  19.                 },  
  20.                 {  
  21.                     "verb""addSPField",  
  22.                     "fieldType""Number",  
  23.                     "displayName""Number Column",  
  24.                     "addToDefaultView"true,  
  25.                     "isRequired"true  
  26.                 },  
  27.                 {  
  28.                     "verb""addSPField",  
  29.                     "fieldType""User",  
  30.                     "displayName""User Column",  
  31.                     "addToDefaultView"true,  
  32.                     "isRequired"true  
  33.                 },  
  34.                 {  
  35.                     "verb""addSPField",  
  36.                     "fieldType""Note",  
  37.                     "displayName""Note Column Notes",  
  38.                     "isRequired"false  
  39.                 }  
  40.             ]  
  41.         }  
  42.     ],  
  43.     "version": 1  
  44. }  
Install SPO Management Shell
 
Click here to download and install SharePoint Online Management Shell.
 
Connect to SharePoint Online
 
Open SPO Management Shell, run the following script to connect to SharePoint Online.
  1. $credentials =Get-Credential  
  2. $tenantURL="https://c986-admin.sharepoint.com"  
  3. Connect-SPOService -Url $tenantURL -credential $credentials  
Add the site script
 
Run the following command to add the site script.
  1. $sitescriptLocation="C:\Users\anavi\Documents\Work\Events\Blogs\SiteDesign\site-script.json"  
  2. Get-Content $sitescriptLocation -Raw | Add-SPOSiteScript -Title "VJ Demo Site Script"   
Copy the site script ID from the PowerShell window.
 
How To Create A Site Design And Site Script For SharePoint Online Modern Team Site 
 
Register the site design
 
Run the following command to create the site design.
  1. Add-SPOSiteDesign -Title "VJ Demo Site Design" -WebTemplate "64" -SiteScripts "a6697967-4e58-47a0-b9b8-58207fbcfd3d" -Description "Creates customer list"   
WebTemplate 64 – Modern Team Site
WebTemplate 68 – Modern Communication Site
Web Template 1 – Team site (no O365 group connected)
 
How To Create A Site Design And Site Script For SharePoint Online Modern Team Site 
 

Create a Modern Team Site

  1. Navigate to the SharePoint admin portal.
  2. Click "Create Site".
  3. Select the Team Site.

    How To Create A Site Design And Site Script For SharePoint Online Modern Team Site
  1. Select VJ Demo Site Design from "choose a design" dropdown. Enter the site name, description and click "Next".

    How To Create A Site Design And Site Script For SharePoint Online Modern Team Site
  1. You can see the custom actions execution progress at the top of the site as shown below.

    How To Create A Site Design And Site Script For SharePoint Online Modern Team Site

    How To Create A Site Design And Site Script For SharePoint Online Modern Team Site
  1. A new list is created successfully as part of this site design.

Summary

 
Thus, in this article, you saw how to create a site design and site script for SharePoint Online Modern Team site.