How Site Template Helps Us To Automate The Creation Of Multiple Department Sites

How Site Template helps us to automate the creation of multiple Department Sites

The basic concept of SharePoint Online:

Nowadays SharePoint Online is highly modernized, it gives options to select desired site designs based on your requirements. If you go to SharePoint Home and click on create a site, a window will pop up asking if you want to create a Team Collaboration site or a Communication site. There was no option for the users to modify/edit their sites previously, which was a big problem for a lot of customers because they wanted to make sure that these sites had things like standard UIs and standard printing or structures that were completely understandable to all of their employees.

That’s why SharePoint gave its customers a new era by introducing Site Designs and Site Scripts, which will help to choose preconfigured set of site designs to apply over a site.

Introduction:

Admins/Users are the ones who can quickly design and launch a site using a customized template. They not only help in standardizing the sites based on department or purpose, but they also help in reducing the time spent in site creation by automating the process.

Creating a new site with a similar structure for a better and enhanced SharePoint Site is much needed. Whenever a new SharePoint site is created, it is very important to take care of consistency. Each new site, for example, may require suitable branding and theming. You may also have detailed site provisioning scripts that need to be applied each time a new site is created, such as utilizing the PnP provisioning engine (to build multiple required site pages with preloaded web parts within it).

Mesh- an AI-powered SharePoint solution empowers admins/users to create multiple departmental sites. We’re utilizing several departmental site/team site templates so that the newly generated SharePoint site will have one predetermined logo, color theme, design, set of lists and libraries, associate with the hub, regional settings, and site permissions (whatever we designate in the site script).

Key Benefits of SharePoint automation:

  • Time spent on effort-intensive processes will be reduced with the help of automation.
  • Configuration of a site will take less time, once the Site Design and/or Site Script is added in SharePoint Online by their organization for its application.
  • Enables user to create Site Designs/Site Scripts that your IT personnel has configured.
  • Site Design/Site Script can be applied to a site several times to keep the site up to date and fresh.
  • Flow is triggered by the action, and then eventually you will grow from the limited operations.

How to choose a site template for a new SharePoint site:

Site Template Assets 1

In the SharePoint window, we can select the defined site template for the new SharePoint site creation. The dropdown contains all the predefined site templates which we can choose and configure.

Site Template Assets 2

The question should strike us now. How is this made possible? How are these site templates made available for a new SharePoint site creation?

Here is a small overview of the process:

Architecture Diagram:

Site Template Assets 3

Now, how to write site scripts associated to a Site Design?

As we want to replicate a site’s predefined logo, colour theme, design, set of lists and libraries, associate with hub site, regional settings, site permissions etc. So, we need to export the site design directly as a site script with the below steps in Powershell for execution.

How to export an existing site design as a site script:

Step1: Open Windows Powershell in the System.

Step2: Write the below lines:

$adminSiteUrl = “https://mytenant-admin.sharepoint.com”

$siteUrl = “https://mytenant.sharepoint.com/sites/sitename”

$relativeListUrls = “/lists/listname”, “/lists/listname-2”, “/lists/listname-3”

Connect-SPOService $adminSiteUrl

Get-SPOSiteScriptFromWeb –WebUrl $siteUrl -IncludeTheme -IncludeBranding -IncludeSiteExternalSharingCapability –IncludeRegionalSettings -IncludeLinksToExportedItems –IncludedLists $relativeListUrls | clip

After executing above lines, a set of data (in json format) will be copied to the clipboard.

Note that this command will not export “page layout and web part configurations” — these features are not yet available in site designs, although they have been mentioned to be implemented sometime in the future.

Sample of Site Script Json:

    “$schema”: “https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json”, 

    “actions”: [{ 

        “verb”: “applyTheme”, 

        “themeName”: “Demo Theme” 

    }, { 

        “verb”: “createSPList”, 

        “listName”: “Demo List”, 

        “templateType”: 100, 

        “subactions”: [{ 

            “verb”: “SetDescription”, 

            “description”: “Demo purpose” 

        }, { 

            “verb”: “addSPField”, 

            “fieldType”: “Text”, 

            “displayName”: “Name”, 

            “isRequired”: false, 

            “addToDefaultView”: true 

        }, { 

            “verb”: “addSPField”, 

            “fieldType”: “Number”, 

            “displayName”: “Marks”, 

            “addToDefaultView”: true, 

            “isRequired”: true 

        }, { 

            “verb”: “addSPField”, 

            “fieldType”: “User”, 

            “displayName”: “Contact”, 

            “addToDefaultView”: true, 

            “isRequired”: true 

        }, { 

            “verb”: “addSPField”, 

            “fieldType”: “Note”, 

            “displayName”: “Meeting Notes”, 

            “isRequired”: false 

        }] 

    }], 

    “version”: 1 

}

The verbs listed in the script are nothing but a set of actions we are mentioning to execute.

We need to copy and paste the json script in a notepad and save it as a json in our local system. We need to make our site script ready now.

As the webpart configurations are not exported, we need to write one Azure Logic App or Microsoft Power Automate to move Sitepages along with the webpart configurations (We will discuss how to write Azure Logic App in later parts of the blog).

Now, we need to add a new verb to execute the Power Automate/Azure Logic App in the Site Script as mentioned below:

    {

            “verb”: “triggerFlow”,

            “url”: “https://prod-24.westeurope.logic.azure.com:443/workflows/a237bcf9…”,

            “name”: “Execute Powershell!!”,

            “parameters”:

            {

               “event”: “Microsoft Event”,

               “product”: “SharePoint”

            }

        }

The json file is ready, which we will use in adding the Site script in our target tenant.

How to add a SiteScript to the tenant using Powershell:

Open Powershell and run the below code with proper data.

$adminSiteUrl = “https://mytenant-admin.sharepoint.com” #Add your tenant admin URL.

$siteScriptFile = “c:\scripts\site-script.json” #File path of JSON file.

$siteScriptTitle = “Sample Site Script”    #Give title to your Site Script.

$cred = Get-Credential

Connect-SPOService $adminSiteUrl -Credential $cred

Get-Content $siteScriptFile -Raw | Add-SPOSiteScript -Title $siteScriptTitle

Once the Site Script is added to the tenant, the details of the site script will be shown. We need to take a note of Site Script ID for later usage.

For the next steps, we need to create a Site Design and attach the Site Script to it. Only then we will have an option of Site Design in the SharePoint Online to create a new site.

How to create a Site Design and attach scripts to it:

$webTemplate = “64” #64 = Team Site, 68 = Communication Site, 1 = Groupless Team Site

# You can pass multiple Site Script IDs as an array.

Add-SPOSiteDesign -Title “Contoso Site Design” -WebTemplate $webTemplate -SiteScripts “127cb6a9-dc14-44d4-8962-d3821d61e802” -Description “Creates list and applies theme.”

Site Script attribute contains the Site Script ID, which is copied from the previous steps

Below is the sample screenshot of execution of the above scripts in PowerShell:

Site Template Assets 4

Now that we have our Site Design and Site Script deployed in our Office 365 tenant and Site Design is ready to use for new site creation and even in the existing sites, we can apply the SiteDesign as mentioned in the beginning.

After choosing the newly created SiteDesign and applying it to the site, a progress bar will appear letting the user know that action is completed, pending, or in the queue to perform.

Here is the screenshot of Site Design update:

Site Template Assets 5

When all the actions are completed, the end user can click view updated site. The user will be directed to the updated site with configured actions applied from the Site Script that is associated to the chosen Site Design.

Key Terms:

  • SiteScript Json
  • SiteScript ID
  • Verbs
  • Triggering PowerAutomate/Azure Logic App
  • JoinHubSite
  • SiteDesign ID
  • Powershell