Introduction To SharePoint Site Design And Site Script

Overview

In the SharePoint Online, we have seen the implementation of Remote Provisioning to provision the SharePoint artifacts (e.g. Site columns, content types, lists, pages, etc.) remotely. In case you missed it, here is the documentation on it - https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/pnp-remote-provisioning

With the introduction of Modern UI to SharePoint online, we were waiting for similar kind of functionality to be released, and now we have the Site Design and Site Script to help us support our custom configuration in Modern UI too.

Microsoft is releasing the Site Design and Site Script features for SharePoint Online to Office 365 tenants. Site Design and Site Script are used to automate the provisioning of SharePoint site using our own custom configurations.

What is Site Design?

We can relate site design as a template, from which we can create a SharePoint site. This template will help us to have consistency across multiple sites to create for a similar purpose.

At the moment, SharePoint Online supports 2 templates out of the box:

  1. Team site
  2. Communication site

Like the old feature of stapling concepts from the On-Premise days, we can attach our custom site design to any of the above templates.

  1. Navigate to SharePoint Online home page of your O365 tenant
  2. Click “Create Site”
  3. We get an option to select any of the Modern site templates

    SharePoint
  1. If we select “Communication Site”, it gives further options to choose the design template.

    SharePoint 

These are the out of box Modern UI site designs, we can choose to create the SharePoint site.

When we select the site design and click create the site, in the background SharePoint runs the site scripts for that selected site design to create the site.

What is Site Script?

Site scripts are JSON files, which define an ordered list of actions to execute while creating the SharePoint site.

The actions can include any combination of below:

  • Create a new list
  • Apply theme
  • Set site logo
  • Add navigation
  • Trigger Microsoft flow

Few points to consider

  • At the moment, no UI is available for Site scripts configuration. We have to deal with Site Scripts from PowerShell only
  • Site Script can be run on same site any number of times
  • Site Scripts are non-destructive. Means, site scripts will add only missing elements to the site (e.g. fields to the list)
  • Site Scripts can have 30 cumulative actions defined.

Examples of Site Script

https://github.com/SharePoint/sp-dev-site-scripts

From the attachment, use Apply-Theme.ps1 to install custom Cyan theme to your tenant. Or use the Theme Generator tool to create your own color theme.

To apply the above theme, we will create the Site Script as below,

  1. {  
  2.     "$schema""schema.json",  
  3.     "actions": [{  
  4.         "verb""applyTheme",  
  5.         themeName: "Custom Cyan"  
  6.     }],  
  7.     "bindata": {},  
  8.     "version": 1  
  9. };  

Also refer to the site-script.json from attachment.

PowerShell to Attach Site Script to Site Design

Now using PowerShell we will attach the site script to the site design

Use below PowerShell to read the Site Script json

Get-Content 'c:\scripts\site-script.json' `
     -Raw | `
     Add-SPOSiteScript `
    -Title "Contoso theme and list"

SharePoint

Note down the Id generated by the Site Script.

Add-SPOSiteDesign `
  -Title "Custom tracking" `
  -WebTemplate "64" `
  -SiteScripts "3aff9f82-fe6c-42d3-803f-8951d26ed854" `
  -Description "Creates list and applies theme"

SharePoint

The WebTemplate 64 is for the team site. Add-SPOSiteDesign registers this site script with the team site template.

Test the Site Design

  1. Navigate to SharePoint Online home page of your O365 tenant
  2. Click “Create Site”
  3. We get an option to select any of the Modern site templates.
  4. Select Team site
  5. We should see our custom site design listed on Team site.

    SharePoint

  6. Select it to create your site.
  7. While provisioning the site, you should see your custom theme being applied and custom lists are being created.
    SharePoint

  8. Once provisioning completes, navigate to site contents to see your custom lists created.

    SharePoint

I hope this helps.