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.
- {
- "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
- "actions": [
- {
- "verb": "createSPList",
- "listName": "VJ Custom List",
- "templateType": 100,
- "subactions": [
- {
- "verb": "SetDescription",
- "description": "VJ Custom List created through Site Design"
- },
- {
- "verb": "addSPField",
- "fieldType": "Text",
- "displayName": "Text Column",
- "isRequired": false,
- "addToDefaultView": true
- },
- {
- "verb": "addSPField",
- "fieldType": "Number",
- "displayName": "Number Column",
- "addToDefaultView": true,
- "isRequired": true
- },
- {
- "verb": "addSPField",
- "fieldType": "User",
- "displayName": "User Column",
- "addToDefaultView": true,
- "isRequired": true
- },
- {
- "verb": "addSPField",
- "fieldType": "Note",
- "displayName": "Note Column Notes",
- "isRequired": false
- }
- ]
- }
- ],
- "version": 1
- }
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.
- $credentials =Get-Credential
- $tenantURL="https://c986-admin.sharepoint.com"
- Connect-SPOService -Url $tenantURL -credential $credentials
Add the site script
Run the following command to add the site script.
- $sitescriptLocation="C:\Users\anavi\Documents\Work\Events\Blogs\SiteDesign\site-script.json"
- Get-Content $sitescriptLocation -Raw | Add-SPOSiteScript -Title "VJ Demo Site Script"
Copy the site script ID from the PowerShell window.
Register the site design
Run the following command to create the site design.
- 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)
Create a Modern Team Site
- Navigate to the SharePoint admin portal.
- Click "Create Site".
- Select the Team Site.
- Select VJ Demo Site Design from "choose a design" dropdown. Enter the site name, description and click "Next".
- You can see the custom actions execution progress at the top of the site as shown below.
- 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.